A minimal filesystem-based publishing engine with Markdown support.
NimblePublisher is a minimal filesystem-based publishing engine with Markdown support and code highlighting.
use NimblePublisher,
build: Article,
from: Application.app_dir(:app_name, "priv/articles/**/*.md"),
as: :articles,
highlighters: [:makeup_elixir, :makeup_erlang]The example above will get all articles in the given directory, call Article.build/3 for each article, passing the filename, the metadata, and the article body, and define a module attribute named @articles with all built articles returned by the Article.build/3 function.
Each article in the articles directory must have the format:
%{
title: "Hello world"
}
---
Body of the "Hello world" article.
This is a *markdown* document with support for code highlighters:
```elixir
IO.puts "hello world".
```
Options
:build- the name of the module that will build each entry:from- a wildcard pattern where to find all entries. Files with the.mdor.markdownextension will be converted to Markdown withEarmark. Other files will be kept as is.:as- the name of the module attribute to store all built entries:highlighters- which code highlighters to use.NimblePublisherusesMakeupfor syntax highlighting and you will need to add its.cssclasses. You can generate the CSS classes by callingMakeup.stylesheet(:vim_style, "makeup")insideiex -S mix. You can replace:vim_styleby any style of your choice defined here.:earmark_options- an%Earmark.Options{}struct:parser- custom module with aparse/2function that receives the file path and content as params. It must return a 2 element tuple with attributes and body.
Examples
Let's see a complete example. First add nimble_publisher with the desired highlighters as a dependency:
def deps do
[
{:nimble_publisher, "~> 0.1.0"},
{:makeup_elixir, ">= 0.0.0"},
{:makeup_erlang, ">= 0.0.0"}
]
end
In this example, we are building a blog. Each post stays in the "posts" directory with the format:
/posts/YEAR/MONTH-DAY-ID.md
A typical blog post will look like this:
# /posts/2020/04-17-hello-world.md
%{
title: "Hello world!",
author: "José Valim",
tags: ~w(hello),
description: "Let's learn how to say hello world"
}
---
This is the post.
Therefore, we will define a Post struct that expects all of the fields above. We will also have a :date field that we will build from the filename.
from https://github.com/dashbitco/nimble_publisher
-----
demo site: https://elixirschool.com/blog
the demo site's source code: https://github.com/elixirschool/elixirschool
No comments:
Post a Comment