Insert File - GrapeCity/metalsmith-one-replace GitHub Wiki

Insert content from another file

There are use cases when a part of the markdown content:

  • is common and should be shared among multiple markdown files
  • or if of HTML (or some other) type - and including it part of markdown make it less readable

In the above conditions, the solution is to keep the content as a separate file, and include it in the markdown during the build process.

With this feature, keep the specific content as separate file, and refer the file using the tag within the markdown.

{#insert ./filename}

This tag {#insert} is a regular expression, customizable, and can be defined in the config.

Usage example with default tag

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>

Custom tag

Config file setting

...
{
    actions:[{
        type:'file',
        keyRegex:'{#file (.*?)}'
    }]
}
...

And considering the files in above mentioned example, change the tag in 'file1.md'.

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

And the final build output will be same.