Skip to content

Commit

Permalink
Merge pull request #13 from Janna112358/add-last-updated
Browse files Browse the repository at this point in the history
Add last updated information
  • Loading branch information
kMutagene authored Oct 4, 2023
2 parents 68e3b8b + 68e530f commit 28dc7cd
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 18 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,17 @@ To add a graph post:
- `summary` is an optional short summary of the post. It is recommended to add for SEO.
- `perview_image` is an optional image that will be shown on post previews. ideally a 2-by-1 or 3-by-1 image with a width of 1200px. It is recommended to add for SEO.
- create a `<language>.ipynb` file that contains your graph post. This notebook will be parsed and rendered to a html site. Ideally, you provide both `fsharp.ipynb` and `csharp.ipynb`, but F#-only is okay as well. **do not forget to save the notebook with cell output**, as the notebook will not be executed on site generation.
- create a `<language>.ipynb` file that contains your graph post. This notebook will be parsed and rendered to a html site. Ideally, you provide both `fsharp.ipynb` and `csharp.ipynb`, but F#-only is okay as well. **do not forget to save the notebook with cell output**, as the notebook will not be executed on site generation.
### update a post
- Update an existing blog or graph gallery post in line with the instructions above.
- Add metadata about the update to the `post_config.md` or `graph_post_config.md` according to this structure:
```
last_updated_on: <YYYY-MM-DD>
last_updated_by: <your name>
last_updated_by_link: <a link>
```
- `last_updated_on` is the date of the last update in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
- `last_updated_by` is an optional name of the contributing author
- `last_updated_by_link` is a optional link that will be associated with the contributing author name. Provide both `last_updated_by` and `last_updated_by_link` to display contributing author information. You can leave them out, for example, if you are updating your own post.
30 changes: 27 additions & 3 deletions src/generators/layout.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let layout (ctx : SiteContents) (metadata: SiteMetadata) active bodyCnt =
Components.Footer()
]

let postLayout (ctx : SiteContents) (metadata: SiteMetadata) (post_category:string) (post_category_url:string) (post_title:string) (post_date:System.DateTime) (post_author:string) (post_author_link: string) (toc:HtmlElement) active heroCnt bodyCnt =
let postLayout (ctx : SiteContents) (metadata: SiteMetadata) (post_category:string) (post_category_url:string) (post_title:string) (post_date:System.DateTime) (post_author:string) (post_author_link: string) (post_updated_at: System.DateTime option) (post_updated_by: string option) (post_updated_by_link: string option) (toc:HtmlElement) active heroCnt bodyCnt =
let pages = ctx.TryGetValues<Pageloader.Page> () |> Option.defaultValue Seq.empty

let ttl = metadata.Title
Expand Down Expand Up @@ -123,6 +123,18 @@ let postLayout (ctx : SiteContents) (metadata: SiteMetadata) (post_category:stri
a [Href post_author_link; Class "is-aquamarine"] [!! post_author]
!! $" in "
a [Href post_category_url; Class "is-aquamarine"] [!! (post_category)]

match post_updated_at with
| Some update_date ->
h4 [Class "substitle is-white is-block"] [
!! $"Last updated on {update_date.Year}-{update_date.Month}-{update_date.Day} "
match post_updated_by, post_updated_by_link with
| (Some updated_author), (Some updated_author_link) ->
!! $"by "
a [ Href updated_author_link; Class "is-aquamarine" ] [ !!updated_author ]
| _, _ -> ()
]
| None -> ()
]
]
yield! heroCnt
Expand Down Expand Up @@ -151,6 +163,9 @@ let standardPostLayout (ctx: SiteContents) (post_config: Postloader.PostConfig)
post_config.date
post_config.author
post_config.author_link
post_config.last_updated_on
post_config.last_updated_by
post_config.last_updated_by_link
toc
active
[]
Expand All @@ -170,13 +185,15 @@ let graphGalleryPostLayout (ctx: SiteContents) (post_config: Graphgallerypostloa
post_config.date
post_config.author
post_config.author_link
post_config.last_updated_on
post_config.last_updated_by
post_config.last_updated_by_link
toc
active
heroCnt
bodyCnt

let postPreview (preview_image_url: string option) (post_summary: string option) (post_url:string) (post_category_url:string) (post_category:string) (post_title:string) (post_date: System.DateTime) (post_author: string) (post_author_link: string) (tags:(string*string) list) =

let postPreview (preview_image_url: string option) (post_summary: string option) (post_url:string) (post_category_url:string) (post_category:string) (post_title:string) (post_date: System.DateTime) (post_author: string) (post_author_link: string) (post_updated_at: System.DateTime option) (tags:(string*string) list) =
let has_image = Option.isSome preview_image_url
let has_summary = Option.isSome post_summary

Expand Down Expand Up @@ -205,6 +222,11 @@ let postPreview (preview_image_url: string option) (post_summary: string option)
a [Href post_author_link; Class "is-aquamarine"] [!! post_author]
!! "in "
a [Href post_category_url; Class "is-aquamarine"] [!! (post_category)]

match post_updated_at with
| Some updated_date ->
div [Class "content"] [!! $"Updated on {updated_date.Year}-{updated_date.Month}-{updated_date.Day}"]
| None -> ()
]
]

Expand All @@ -220,6 +242,7 @@ let standardPostPreview (post: Postloader.NotebookPost) =
post.post_config.date
post.post_config.author
post.post_config.author_link
post.post_config.last_updated_on
[]

let graphGalleryPostPreview (post: GraphGalleryPost) =
Expand All @@ -233,6 +256,7 @@ let graphGalleryPostPreview (post: GraphGalleryPost) =
post.post_config.date
post.post_config.author
post.post_config.author_link
post.post_config.last_updated_on
(post.file_names |> Array.toList |> List.map (fun (lang, path) -> lang, Globals.prefixUrl $"graph-gallery/{path}"))

let render (ctx : SiteContents) cnt =
Expand Down
28 changes: 21 additions & 7 deletions src/loaders/graphgallerypostloader.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ type GraphGalleryPostConfig = {
date: System.DateTime
preview_image: string option
summary: string option
last_updated_on: System.DateTime option
last_updated_by: string option
last_updated_by_link: string option
} with
static member create(title, author, author_link, category, date, ?preview_image, ?summary) =
static member create(title, author, author_link, category, date, ?preview_image, ?summary, ?last_updated_on, ?last_updated_by, ?last_updated_by_link) =
{
title = title
author = author
Expand All @@ -61,10 +64,18 @@ type GraphGalleryPostConfig = {
date = date
preview_image = preview_image
summary = summary
last_updated_on = last_updated_on
last_updated_by = last_updated_by
last_updated_by_link = last_updated_by_link
}
static member ofMap (source:string) (m:Map<string,string>) =

let mandatoryFieldMissing (fieldName: string) (source:string) (o:string Option) = if o.IsNone then failwith $"missing field '{fieldName}' in config from {source}" else o.Value
let parseDateString(dateString: string) =
try
System.DateTime.ParseExact(dateString,"yyyy-MM-dd",System.Globalization.CultureInfo.InvariantCulture)
with _ ->
failwith $"wrong date format in config from {source}, make sure to use YYY-MM-DD"

let title =
m
Expand All @@ -84,23 +95,26 @@ type GraphGalleryPostConfig = {
with _ ->
failwith $"wrong post category format in config from {source}"
let date =
let tmp = m.TryFind "date" |> mandatoryFieldMissing "date" source
try
System.DateTime.ParseExact(tmp,"yyyy-MM-dd",System.Globalization.CultureInfo.InvariantCulture)
with _ ->
failwith $"wrong date format in config from {source}, make sure to use YYY-MM-DD"
m.TryFind "date" |> mandatoryFieldMissing "date" source |> parseDateString

let preview_image = m |> Map.tryFind "preview_image"
let summary = m |> Map.tryFind "summary"

let last_updated_on = m.TryFind "last_updated_on" |> Option.map parseDateString
let last_updated_by = m.TryFind "last_updated_by"
let last_updated_by_link = m.TryFind "last_updated_by_link"

GraphGalleryPostConfig.create(
title = title,
author = author,
author_link = author_link,
category = category,
date = date,
?preview_image = preview_image,
?summary = summary
?summary = summary,
?last_updated_on = last_updated_on,
?last_updated_by = last_updated_by,
?last_updated_by_link = last_updated_by_link
)

type GraphGalleryPost = {
Expand Down
28 changes: 21 additions & 7 deletions src/loaders/postloader.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ type PostConfig = {
date: System.DateTime
preview_image: string option
summary: string option
last_updated_on: System.DateTime option
last_updated_by: string option
last_updated_by_link: string option
} with
static member create(title, author, author_link, category, date, ?preview_image, ?summary) =
static member create(title, author, author_link, category, date, ?preview_image, ?summary, ?last_updated_on, ?last_updated_by, ?last_updated_by_link) =
{
title = title
author = author
Expand All @@ -49,10 +52,18 @@ type PostConfig = {
date = date
preview_image = preview_image
summary = summary
last_updated_on = last_updated_on
last_updated_by = last_updated_by
last_updated_by_link = last_updated_by_link
}
static member ofMap (source:string) (m:Map<string,string>) =

let mandatoryFieldMissing (fieldName: string) (source:string) (o:string Option) = if o.IsNone then failwith $"missing field {fieldName} in config from {source}" else o.Value
let parseDateString(dateString: string) =
try
System.DateTime.ParseExact(dateString,"yyyy-MM-dd",System.Globalization.CultureInfo.InvariantCulture)
with _ ->
failwith $"wrong date format in config from {source}, make sure to use YYY-MM-DD"

let title =
m
Expand All @@ -72,23 +83,26 @@ type PostConfig = {
with _ ->
failwith $"wrong post category format in config from {source}"
let date =
let tmp = m.TryFind "date" |> mandatoryFieldMissing "date" source
try
System.DateTime.ParseExact(tmp,"yyyy-MM-dd",System.Globalization.CultureInfo.InvariantCulture)
with _ ->
failwith $"wrong date format in config from {source}, make sure to use YYY-MM-DD"
m.TryFind "date" |> mandatoryFieldMissing "date" source |> parseDateString

let preview_image = m |> Map.tryFind "preview_image"
let summary = m |> Map.tryFind "summary"

let last_updated_on = m.TryFind "last_updated_on" |> Option.map parseDateString
let last_updated_by = m.TryFind "last_updated_by"
let last_updated_by_link = m.TryFind "last_updated_by_link"

PostConfig.create(
title = title,
author = author,
author_link = author_link,
category = category,
date = date,
?preview_image = preview_image,
?summary = summary
?summary = summary,
?last_updated_on = last_updated_on,
?last_updated_by = last_updated_by,
?last_updated_by_link = last_updated_by_link
)
type NotebookPost = {
file_name: string
Expand Down
3 changes: 3 additions & 0 deletions src/posts/getting-started/post_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ author: David Zimmer
author_link: https://github.com/ZimmerD
category: datascience
date: 2021-02-09
last_updated_on: 2023-09-30
last_updated_by: Jay Goldstein
last_updated_by_link: https://github.com/Janna112358
---

0 comments on commit 28dc7cd

Please sign in to comment.