access to original "contents"
justb3a opened this issue · comments
Hi,
if I want to access the contents
property of a page in another page, I get the whole rendered html output. I couldn't find a way to get just the parsed (markdown) content of the related content file because the convert
function of this plugin overrides the data.contents
property (:144).
Is there a possibility to backup the original content? For example by adding a line above like this:
data.contentsOrig = new Buffer(data.contents);
data.contents = new Buffer(str);
use case
template (handlebars with a little helper function to get the first item of a collection):
partial:
This sometimes renders the page inside the page because {{{item.contents}}}
returns something like this:
<!DOCTYPE html>
<html class="no-js" lang="de">
<head>
<meta charset="utf-8" /> ...
instead of
<h2>headline</h2>
<p>content</p>
Another use case is that I need all contents of this collection inside a specific json structure to make it available as an "api endpoint".
...
obj.forEach((item) => {
const current = {
title: item.title,
contents: item.contents // Buffer including the complete page
contents: item.contentsOrig // Buffer including just the content of the parsed md file
};
...
});
Maybe there is another way to solve this issue or maybe I overlooked something...
Thanks in advance!
Found a plugin that totally fits my needs 👍
Plugin: metalsmith-untemplatize
- A Metalsmith plugin to extract untemplatized file contents
- This can be pretty useful when you need to access file contents without any template rendering in other templates