diff --git a/README.org b/README.org index e8adfa6..607eda7 100644 --- a/README.org +++ b/README.org @@ -1,14 +1,25 @@ * go-org [[https://travis-ci.org/niklasfasching/go-org.svg?branch=master]] -An Org mode parser in go. And soon a blog generator. -Take a look at [[https://niklasfasching.github.io/go-org/][github pages]] for some examples and to try it out live in your browser. +An Org mode parser and static site generator in go. +Take a look at github pages +- for [[https://niklasfasching.github.io/go-org/][org to html conversion]] examples +- for a [[https://niklasfasching.github.io/go-org/blorg][static site]] generated by blorg +- to [[https://niklasfasching.github.io/go-org/convert.html][try it out live]] in your browser + [[https://raw.githubusercontent.com/niklasfasching/go-org/master/etc/example.png]] + Please note - the goal for the html export is to produce sensible html output, not to exactly reproduce the output of =org-html-export=. - the goal for the parser is to support a reasonable subset of Org mode. Org mode is *huge* and I like to follow the 80/20 rule. * usage ** command line -#+begin_src -go-org +#+begin_src bash +$ go-org +USAGE: org COMMAND [ARGS] +- org render FILE OUTPUT_FORMAT + OUTPUT_FORMAT: org, html, html-chroma +- org blorg init +- org blorg build +- org blorg serve #+end_src ** as a library see [[https://github.com/niklasfasching/go-org/blob/master/main.go][main.go]] and hugo [[https://github.com/gohugoio/hugo/blob/master/markup/org/convert.go][org/convert.go]] diff --git a/blorg/config.go b/blorg/config.go index 65c3e59..1524667 100644 --- a/blorg/config.go +++ b/blorg/config.go @@ -24,6 +24,7 @@ type Config struct { ContentDir string PublicDir string Address string + BaseUrl string Template *template.Template OrgConfig *org.Configuration } @@ -52,7 +53,7 @@ var TemplateFuncs = map[string]interface{}{ } func ReadConfig(configFile string) (*Config, error) { - address, publicDir, contentDir, workingDir := ":3000", "public", "content", filepath.Dir(configFile) + baseUrl, address, publicDir, contentDir, workingDir := "/", ":3000", "public", "content", filepath.Dir(configFile) f, err := os.Open(configFile) if err != nil { return nil, err @@ -63,6 +64,9 @@ func ReadConfig(configFile string) (*Config, error) { return nil, document.Error } m := document.BufferSettings + if !strings.HasSuffix(m["BASE_URL"], "/") { + m["BASE_URL"] += "/" + } if v, exists := m["AUTO_LINK"]; exists { orgConfig.AutoLink = v == "true" delete(m, "AUTO_LINK") @@ -71,6 +75,9 @@ func ReadConfig(configFile string) (*Config, error) { address = v delete(m, "ADDRESS") } + if _, exists := m["BASE_URL"]; exists { + baseUrl = m["BASE_URL"] + } if v, exists := m["PUBLIC"]; exists { publicDir = v delete(m, "PUBLIC") @@ -87,6 +94,7 @@ func ReadConfig(configFile string) (*Config, error) { orgConfig.MaxEmphasisNewLines = i delete(m, "MAX_EMPHASIS_NEW_LINES") } + for k, v := range m { if k == "OPTIONS" { orgConfig.DefaultSettings[k] = v + " " + orgConfig.DefaultSettings[k] @@ -94,11 +102,13 @@ func ReadConfig(configFile string) (*Config, error) { orgConfig.DefaultSettings[k] = v } } + config := &Config{ ConfigFile: configFile, ContentDir: filepath.Join(workingDir, contentDir), PublicDir: filepath.Join(workingDir, publicDir), Address: address, + BaseUrl: baseUrl, Template: template.New("_").Funcs(TemplateFuncs), OrgConfig: orgConfig, } @@ -174,7 +184,8 @@ func (c *Config) RenderContent() ([]*Page, error) { return err } pages = append(pages, p) - p.PermaLink = "/" + relPath[:len(relPath)-len(".org")] + ".html" + + p.PermaLink = c.BaseUrl + relPath[:len(relPath)-len(".org")] + ".html" return p.Render(publicPath[:len(publicPath)-len(".org")] + ".html") }) sort.Slice(pages, func(i, j int) bool { return pages[i].Date.After(pages[j].Date) }) diff --git a/blorg/testdata/blorg.org b/blorg/testdata/blorg.org index 8e2b53a..76c97d3 100644 --- a/blorg/testdata/blorg.org +++ b/blorg/testdata/blorg.org @@ -1,7 +1,7 @@ -#+AUTHOR: author -#+TITLE: blog -#+BASE_URL: https://www.example.com -#+OPTIONS: toc:nil +#+AUTHOR: testdata +#+TITLE: blorg +#+BASE_URL: /go-org/blorg +#+OPTIONS: toc:nil title:nil #+CONTENT: ./content #+PUBLIC: ./public @@ -12,7 +12,7 @@
- +