Skip to content

Instantly share code, notes, and snippets.

@clarete
Last active August 28, 2020 02:12
Show Gist options
  • Save clarete/5a7b4375e8ecd0d1683185b95ca4deaa to your computer and use it in GitHub Desktop.
Save clarete/5a7b4375e8ecd0d1683185b95ca4deaa to your computer and use it in GitHub Desktop.
Proposal for blorg's API that's aware of HTTP endpoints

Just a file to be linked to

If you didn’t like it, you can go back To where you whence were

Github won’t render the link above properly, gotta see the raw content

Now we’re in an Org-Mode documentation

This documentation links to another documentation using custom handlers.

Github won’t render the link above properly, gotta see the raw content

Within Org-Mode files, as you may have seen above (or not if you’re on github), this is what one needs to write to link from one Org-Mode file to another using blorg’s awareness of routes:

[[url:docs,slug=another-doc][links to another documentation]]
  • url is the custom handler created by blorg and registered within Org-Mode right before parsing a .org file;
  • docs is the :route’s :name parameter;
  • slug is the variable that :url needs to be interpolated correctly
(require 'blorg)
(blog-site
:base-url (if (string= (getenv "ENV") "prod")
"https:/clarete.li/blorg"
"http://localhost:8000")
:route (list
:name "index"
:input-pattern "docs/.*\\.org$"
:template "index.html"
:output "index.html"
:url "/")
:route (list
:name "docs"
:input-pattern "docs/.*\\.org$"
:template "post.html"
:output "docs/{{ slug }}.html"
:url "/docs/{{ slug }}.html")
:route (list
:name "api"
:template "autodoc.html"
:output "docs/api.html"
:url "/docs/api.html"
:input-source (blorg-input-source-autodoc-sections
`(("Start a New Project" . "^blorg-new$")
("HTML Generation" . ,(concat "blorg-" (regexp-opt '("gen" "cli"))))
("Filter Functions" . "^blorg-input-filter-")
("Aggregation Functions" . "^blorg-input-aggregate-")
("Input Sources" . "^blorg-input-source-"))))
:route (list
:name "assets"
:input-source (blorg-input-source-assets 'local 'blorgs)
:output "assets/{{ filename }}"
:url "/assets/{{ filename }}"))
<html>
<h1>Within a template</h1>
<ul>
{# This will render http://localhost:8000/ #}
<li><a href="{{ url_for("index") }}">Home</a></li>
{# This will render http://localhost:8000/docs/doc.html #}
<li><a href="{{ url_for("docs", slug="doc") }}">Doc</a></li>
{# This will render http://localhost:8000/docs/another-doc.html #}
<li><a href="{{ url_for("docs", slug="another-doc") }}">Another doc</a></li>
</ul>
</html>
{# the function url_for() takes one required parameter, the name of the route,
and then it takes a series of keyword arguments that are going to be passed
down to the template within the ~:output~ field of the route with the name
in the first argument. #}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment