notes | journal | about | archive | sourcehut | github

Publishing a website from Org-mode

  • editing webpages
  • go-org
  • properties
  • dates
  • bugs/idiosyncrasies
  • Technical notes about my Org-mode and go-org setup. Still a work in progress.

    editing webpages

    There are some differences when writing a page in Org mode instead of Markdown:

    go-org

    Niklas Fasching's go-org is a remarkably complete parser, making it easy to generate a website with a simple Go script. I've been running through a couple of files like drafts.org, posts.org, and journal.org and creating a new page for each top level heading.

    d1 := org.New().Parse(f, "./") // new org.Document
    
    for _, heading := range d1.Nodes { // for each heading in the file
    	
    	// pull full content of the heading as a new org.Document
    	input := strings.NewReader(heading.String())
    	d := org.New().Parse(input, "./")
    

    properties

    To add metadata to a post, just use org-set-property on the heading, which will add a new entry to the PROPERTIES drawer. For Boolean values I've just been adding a key with an empty value if it's true, otherwise my code assumes it's false. This way you can easily add keywords, summaries, and other meta tags. From the previous example, the properties would be stored at d.Outline.Children[0].Headline.Properties.

    dates

    You can store dates in the PROPERTIES drawer, of course, but if you want the title of a post to be a formatted date, just insert a timestamp (C-c .) and use something like this to reformat:

    	layoutUS  := "January 2, 2006"
    	
    	// set title
    	switch t := d.Outline.Children[0].Headline.Title[0].(type) {
    	case org.Timestamp: x.title = t.Time.Format(layoutUS) // format the date if the title is a timestamp
    	default: x.title = t.String() // otherwise just use the heading as the title
    	}
    

    bugs/idiosyncrasies

    A multiline list item followed by a heading needs to be indented extra, otherwise the heading will show up as part of the list:

    - item 1
    - item 2, a multiline item Lorem ipsum dolor sit amet, consectetur 
        adipiscing elit. Aenean quis semper orci. Aenean a est eu est
        dapibus. Nam felis libero, dapibus a maximus ut, condimentum .
    
     * Heading