
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
node-red-contrib-static-markdown
Advanced tools
Serve up a folder of static markdown files from Node-RED
Serve up a folder of static markdown files from Node-RED.
In the admin panel for the node instance, provide a url path and a source folder.
The source folder can contain sub-folders. Files with an extension of .md
will be served as web pages.
Each folder may contain a file named index.md
and if so, this will be used as the default page for that folder.
A .templates
folder can contain Handlebars templates used to render the content. There is a default template if you don't want to bother.
The source files can contain any valid CommonMark markup (provided by the markdown-it) and may also contain metadata in a YAML header. e.g.
---
title: This is the title for my markdown file
---
# My markdown file
This file will be served as HTML with the help of Node-RED.
The parsed YAML data is passed through to the Handlebars template engine and so is available in custom templates.
A number of markup extensions have been installed, see docs/details.md for details.
Notes
markdown-it
is the library used already by Node-RED to handle markdown processing.docs/test-md-library
. You can use the contents to test this node, copy to your selected source folder. In addition, the folder contains a file test.md
which demonstrates the majority of the markdown and extensions available to you.Similarly to Node-RED's built-in static file serving, if a folder name is given in the URL instead of a filename, /index.md
will be automatically appended.
The root source folder is mounted using ExpressJS static-server
in the same way as Node-RED's httpStatic
setting. This means that files ending in .html
, .js
, .css
, etc. will all be served as normal. You can use this not only to display html content but also to load CSS styling and JavaScript via custom templates.
Each markdown file is wrapped in a template that is provided by Handlebars.
The source files folder may contain a sub-folder named .templates
. If it does, it should contain a one or more Handlebars template files.
If the .templates
folder does not exist, a file in the source folder called .template.hbs
will be looked for. If that also doesn't exist, an internal default template will be used.
Template files will be searched for in the following order:
.templates
& Folder & filename (ending in .hbs
instead of .md
) matching the requested markdown filename.templates
& Folder & index.hbs
.templates
& Parent folder & index.hbs
- right back up the parents tree to ....templates
& root source folder & index.hbs
.template.hbs
Note that Node-RED must be restarted if new templates are added. Redeploying the flows using the editor menu is not sufficient.
In addition to the translated markdown, the following metadata is provided to the Handlebars templating engine so that it can be used in custom templates:
template
: Template filename used to render the file. You may overwrite this by including an entry of the same name in your frontMatter.stylesheet
: The URL for the default stylesheet made available automatically. You may overwrite this by including an entry of the same name in your frontMatter.prismstyles
: Stylesheet URL for Prism syntax highlighting. You may overwrite this by including an entry of the same name in your frontMatter.mtime
: The date/time the file was last changedfrontMatter
: An object containing properties from the YAML frontmatter. The title
variable is included in the default template.fmPre
: A JSON.stringify'd version of the frontmatter suitable for debugging & understanding what frontmatter is availableThe following is an example template showing content and metadata:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{frontMatter.title}}</title>
<link rel="stylesheet" href="{{stylesheet}}">
<link rel="stylesheet" href="{{prismstyles}}">
</head><body>
{{{content}}}
<hr>
<h2>Meta Data</h2>
<dl>
<dt>Stylesheet</dt> <dd>{{stylesheet}}</dd>
<dt>Prism Styles (Syntax Highlighting)</dt> <dd>{{prismstyles}}</dd>
<dt>Template</dt> <dd>{{template}}</dd>
<dt>Date/Time Modified</dt> <dd>{{mtime}}</dd>
</dl>
<h2>Front Matter</h2>
<pre>{{fmPre}}</pre>
</body>
</html>
Notes:
There are still some enhancements that I want to add:
.template.hbs
to exist anywherex-red
to html
- Minimum Node-RED version is now v0.19@gerhobbelt/markdown-it-emoji
and replace with standard version as @gerhobbelt version requires a build stepFAQs
Serve up a folder of static markdown files from Node-RED
We found that node-red-contrib-static-markdown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.