Skip to content

Commit

Permalink
When exporting html, also export deltos source files
Browse files Browse the repository at this point in the history
The plan is that deltos can then import these to allow easy document
sharing. -POLM
  • Loading branch information
polm committed Mar 26, 2016
1 parent 5081082 commit e6bc00b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
14 changes: 13 additions & 1 deletion lib/entries.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions lib/html.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/entries.ls
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export get-all-entries = memoize ->

return values entries |> sort-by (.date) |> reverse

export get-raw-entry = ->
[head, body] = get-entry-parts it
return [(yaml head), body]

get-entry-parts = ->
text = fs.read-file-sync (get-filename it), \utf-8
head = text.split("\n---\n").0
body = text.split("\n---\n")[1 to].join "\n---\n"
return [head, body]

get-new-id = ->
# get a new uuid
# check it doesn't exist; if it does, make another
Expand Down
17 changes: 13 additions & 4 deletions src/html.ls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fs = require \fs
Markdown = require(\markdown-it)(html: true)
markdown = -> Markdown.render it
{memoize, is-in, tagged, yaml, deltos-home, read-config} = require \./util
{get-all-entries} = require \./entries
{memoize, is-in, tagged, yaml, yaml-dump, deltos-home, read-config} = require \./util
{get-all-entries, get-raw-entry} = require \./entries
{map, take, sort-by, sort-with, reverse} = require \prelude-ls

# placeholder globals; only required as needed
Expand Down Expand Up @@ -217,8 +217,17 @@ build-hierarchical-list = (entries, depth, parent=null) ->
build-site-html = (root, entries) ->
# update individual post html
for entry in entries
fname = root + "/by-id/" + entry.id + ".html"
fs.write-file-sync fname, render entry
suffix = "/by-id/#{entry.id}"

html-fname = "#{root}#{suffix}.html"
fs.write-file-sync html-fname, render entry

# write a deltos source file for other people to import
[head, body] = get-raw-entry entry.id
head.source = "#{read-config!.url}#{suffix}.html"
deltos-fname = "#{root}#{suffix}.deltos"
output = (yaml-dump head) + "---\n" + body
fs.write-file-sync deltos-fname, output

build-rss = (root, config, entries) ->
rss = new RSS {
Expand Down
5 changes: 5 additions & 0 deletions src/util.ls
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export yaml = ->
# uuids like "06382" being interpreted as octal
Yaml.safe-load it, schema: Yaml.FAILSAFE_SCHEMA

export yaml-dump = ->
# flowlevel controls how compact the exported yaml is
# as with reading, we only expect strings
Yaml.safe-dump it, schema: Yaml.FAILSAFE_SCHEMA, flow-level: 1

# simple memoizer for thunks
export memoize = (func) ->
output = null
Expand Down

0 comments on commit e6bc00b

Please sign in to comment.