Still.Preprocessor behaviour (Still v0.2.0) View Source
Defines functions to be used by the several preprocessors as well as the behaviour they should have.
Preprocessors are the cornerstone of Still. A preprocessor chain can take a markdown file, execute its embedded Elixir, extract metadata from its front matter, transform it into HTML and wrap it in a layout.
The default preprocessor chain is the following:
%{
".slim" => [AddContent, EEx, Frontmatter, Slime, OutputPath, AddLayout, Save],
".slime" => [AddContent, EEx, Frontmatter, Slime, OutputPath, AddLayout, Save],
".eex" => [AddContent, EEx, Frontmatter, OutputPath, AddLayout, Save],
".css" => [AddContent, EEx, CSSMinify, OutputPath, URLFingerprinting, AddLayout, Save],
".js" => [AddContent, EEx, JS, OutputPath, URLFingerprinting, AddLayout, Save],
".md" => [AddContent, EEx, Frontmatter, Markdown, OutputPath, AddLayout, Save],
".jpg" => [OutputPath, Image],
".png" => [OutputPath, Image]
}
If the default preprocessors are not enough, you can extend Still with your own.
A custom preprocessor is simply a module that calls use Still.Preprocessor
and implements the render/2
and extension/1
functions.
Take the following example:
defmodule YourSite.JPEG do
use Still.Preprocessor
@impl true
def extension(_), do: ".jpeg"
@impl true
def render(file) do
file
end
end
In this example, the render/1
function is used to transform the content and
the metadata of a file, and the extension/1
function is used to set the
resulting content type. This extension/1
function is not mandatory.
See the preprocessor guide for more details.
Link to this section Summary
Functions
Retrieves the preprocessor pipeline for the given file.
Runs the preprocessor pipeline for the given file.
Link to this section Functions
Retrieves the preprocessor pipeline for the given file.
Specs
run(Still.SourceFile.t()) :: Still.SourceFile.t()
Runs the preprocessor pipeline for the given file.
Specs
run(Still.SourceFile.t(), [module()]) :: Still.SourceFile.t()
Link to this section Callbacks
Specs
extension(Still.SourceFile.t()) :: String.t()
Specs
render(Still.SourceFile.t()) :: Still.SourceFile.t()