Skip to content

Allow blog posts to specify an explicit URL slug #960

Description

@berberman

I have some posts with non-English titles, but I'd like their URLs to use short ASCII slugs. Currently the sulg is computed from the post title:

def defaultPostName (date : Date) (title : String) : String :=
s!"{date.year}-{date.month}-{date.day}-{slugifyTitle title}"
structure Config where
destination : System.FilePath := "./_site"
showDrafts : Bool := false
postName : Date → String → String := defaultPostName
remoteInfoConfigPath : Option System.FilePath := none
verbose : Bool := false
deriving Inhabited

While overriding postName can customize the generated name, it only gets the date and title, so the slug has to live somewhere else. And more importantly, Config now seems to be an internal thing:

def blogMain (theme : Theme) (site : Site) (linkTargets : Code.LinkTargets TraverseContext := {})
(options : List String) (components : Components := by exact %registered_components)
(header : String := Html.doctype) :
IO UInt32 :=
withLogger fun logger => do
let cfg ← opts {} options
let (site, xref) ← site.traverse cfg components |>.run logger

There's no way to pass it as argument, so I'm not sure how to modify postName.

I thought it would be nice to add an optional slug to Post.Meta, so this would get /blog/1980-01-01-test/ naturally:

#doc (Post) "测试" =>

%%%
authors := ["foo"]
date := { year := 1980, month := 1, day := 1 }
slug := "test"
%%%

But I'm not sure if there's already a good way to extend post metadata downstream (without defining a new blog genre).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions