Skip to content
Jacob Chirayil edited this page Feb 13, 2019 · 8 revisions

Welcome to the metalsmith-one-replace wiki!

A single Metalsmith/markdown plugin to perform multiple types of replace action within markdown files. The supported replace functions are:

  • Insert content from other file
  • Variable substitution
  • Regex replacement

Feature List

Inserting content from another file

file: copyright.txt

Copyright (c) 2019 Acme Inc. All rights reserved.

file: file1.md

---
title: File1
---
File with copyright notice.
{#insert copyright.txt}

output: file1.html

<p>Another file with copyright notice.</p>
<p>Copyright (c) 2019 Acme Inc. All rights reserved.</p>

Variable

Use case 1 - variables are declared as part of the .md file

Advantage - variables declared as part of yaml and can be referenced multiple time within the document.

file: file1.md

---
title: File1
user1: John Smith
user2: Jane Smith
---
File with variable.
The two authorized users are {#var user1} and {#var user2}. The primary user - {#var user1} - can enable/disable the account of {#var user2}.

output: file1.html

<p>File with variable.</p>
<p>The two authorized users are John Smith and Jane Smith. The primary user - John Smith - can enable/disable the account of Jane Smith.</p>

Use case 2 - variables are declared as part of config

Advantage - variables can be shared between multiple files

config setting

...
var varreplace = require('metalsmith-var-replace');
...
    .use(varreplace({
        actions:[{
            type:'var',
            varValues: {
                'adminuser':'John Smith',
                'fruit':'apple'
            }
        }]
    })
...

file: file1.md

---
title: File1
---
File with variable (values defined about config level).
The name of the administrator is {#var adminuser} and his/her favorite fruit is {#var user2}.

output: file1.html

<p>File with variable (values defined about config level).</p>
<p>The name of the administrator is John Smith and his/her favorite fruit is apple.</p>

Regex Replacement

Clone this wiki locally