~subsetpark/bagatto

3ab1647981984556aaf4e2678d549eb83c302dcb — Zach Smith 4 months ago f2f7bf4
Add vendoring demo
M .gitignore => .gitignore +1 -1
@@ 1,3 1,3 @@
/build
/janet_modules
/demo/site/
/demo/*/site

M bagatto.janet => bagatto.janet +3 -2
@@ 390,9 390,10 @@

(defn markdown->html
  "Render a markdown string into HTML."
  [md &opt opts]
  [md &keys {:opts opts :exts exts}]
  (default opts [:footnotes :smart])
  (markable/markdown->html (string md) opts))
  (default exts [])
  (markable/markdown->html (string md) opts exts))

(defn mmarkdown->html
  ```

A demo/vendoring/about.md => demo/vendoring/about.md +9 -0
@@ 0,0 1,9 @@
{:title "About Bagatto"
 :author "Z. D. Smith"
 :date "2020-12-29"}
 
%%%

## About Bagatto

Bagatto is a cutting-edge site generator.

A demo/vendoring/index.janet => demo/vendoring/index.janet +24 -0
@@ 0,0 1,24 @@
# This site manages dependencies with `project.janet`. We can then use
# `jpm deps` to draw down dependencies as with a normal Janet project.
#
# Running `bag index.janet` will fail if `mago` is not
# available. However, we can make it available by either:
#
# 1. Using `jpm` to install it globally;
# 2. Using `JANET_PATH=... jpm` to install it locally, and then
#    setting the `JANET_PATH` env var when we invoke `bag` as well.
#
# In this example, I've set `JANET_PATH=janet_modules` and installed
# my dependencies to that folder.
(import mago)

(defn parse-mago
  [src attrs]
  (let [{:front front :body body} (mago/parse src)]
    (put attrs :body body)
    (merge-into attrs front)))

(def data {:pages {:src (bagatto/slurp-* "*.md") :attrs parse-mago}})
(def site {:pages {:each :pages
                   :dest (bagatto/%p '%i :title '% ".html")
                   :out (bagatto/renderer "templates/page") }})

A demo/vendoring/janet_modules/mago.janet => demo/vendoring/janet_modules/mago.janet +31 -0
@@ 0,0 1,31 @@
(def default-separator "%%%")

(defn peg
  [separator]
  (peg/compile ~(* (<- (to ,separator))
                   ,separator
                   (<- (any 1)))))

(def default-peg (peg default-separator))

(def- boot-parse parse)

(defn parse
  ```
  Parse a Mago document into Janet frontmatter and arbitrary body text.

  The text before the separator is treated as a single Janet term and
  parsed. The text after the separator is left untouched.

  Accepts an optional second argument to specify the separator string
  to use. The default is `%%%`.
  ```
  [src &opt separator]
  (default separator default-separator)
  (let [peg (case separator
              default-separator default-peg
              (peg separator))
        matched (peg/match peg src)]
    (match matched
      [front body] {:front (boot-parse front) :body body}
      {:front {} :body src})))

A demo/vendoring/project.janet => demo/vendoring/project.janet +9 -0
@@ 0,0 1,9 @@
(declare-project
 :name "my bagatto site"
 :description "a blog"
 :author "Z. D. Smith"
 :dependencies [
                # A Janet-only dependency
                "https://git.sr.ht/~subsetpark/mago"
                # A native dependency
                "https://github.com/joy-framework/moondown.git"])

A demo/vendoring/templates/page.temple => demo/vendoring/templates/page.temple +1 -0
@@ 0,0 1,1 @@
{- (bagatto/markdown->html (get-in args [:_item :body])) -}

M lockfile.jdn => lockfile.jdn +1 -1
@@ 6,4 6,4 @@
  {:sha "b6dd2f3dcfebd26b027234a84029ee099b83b1f0" :repo "https://github.com/janet-lang/path.git"}
  {:sha "61437d96b5df6eb7e524f88847e7d7521201662d" :repo "https://github.com/janet-lang/json.git"}
  {:sha "4226a4cae548fde38358aa1fdb6d6a90bf5fe175" :repo "https://github.com/andrewchambers/janet-sh.git"}
  {:sha "8d55732726332c3ae86fb934b2e8c9c10327be72" :repo "https://github.com/pyrmont/markable"}]
  {:sha "6efa582a6ab4ba12cf13f9dfbd7944596e024bfd" :repo "https://github.com/pyrmont/markable"}]