metalsmith / metadata Goto Github PK
View Code? Open in Web Editor NEWA metalsmith plugin to load global metadata from files.
License: MIT License
A metalsmith plugin to load global metadata from files.
License: MIT License
I'm considering writing a separate plugin to import package.json
as metadata. Would it be a better to just fork the repo and add it?
What does the property category do?
I have the following, as shown in the readme:
.use(metadata({
templatedata: 'templatedata.yaml'
}))
and
templatedata.yaml in the 'src' directory (containing varname: value)
But varname when used in a template is not recognised
I think I just need to do more, but I can not see an example of use (and that is something that can help others too).
EDIT: tried also with .json and json data form, same result. No global metadata (at least not available to templates)
my metalsmith.json
:
"metalsmith-metadata": {
"site": "json/site.json",
"author": "json/author.json",
"photos": "yaml/photos.yaml",
"works": "yaml/works.yaml"
}
site
, author
parse correctly and are being passed to Handlebars, but yaml
files are not. i have checked all files (both .json
and .yaml
) with JSONLint and YAMLint, and they are all valid.
i even tried parsing only one yaml
file, but it didn't work. any ideas?
Some metadata imported from a json file could be useful in the build script, for example as a parameter for some other modules.
Can we use metadata in build script ? If yes, how ?
In my case, I need this feature when I use the metalsmith-feed plugin :
destination
parameter that represent the file path to write the rendered XML feedI want to declare the path once in the json file of metadata and use the var at both places :
It'd be great if there were an option to preprocess markdown in metadata. At the moment it's a difficult thing to do with metalsmith.
Use case:
Excel/Google sheet worksheets saved as CSV/TSV
Hello,
I'm encountering an issue when using this plugin along with the metalsmith-watch
plugin.
The problem is that the metalsmith-watch
plugin calls the middleware stack and only passes the files that actually changed (which is the expected behavior). Therefore when metalsmith-metadata
try to loads the desired metadata files, they do not exists anymore (unless they have been edited). And so it throws an error.
It would be good if the Readme made it clearer that the metadata files in question need to be loaded in the metalsmith 'tree', e.g. in your src
directory if using default options. Took me a while to figure this out - had to look at the source.
As you invoke metalsmith on __dirname
I think you could reasonably expect it to find metadata files relative to there (I did).
You might also expect absolute file paths to work (perhaps if invoking from some higher-level tool, gulp etc) and of course they don't for the same reason. I think this is reasonable, but should probably be noted as well.
Thanks!
Similar to @metalsmith/markdown, provide engineOptions
to pass to the parse function
Similar to @metalsmith/sass and @metalsmith/js-bundle use the entries
option.
Similar to @metalsmith/markdown's render option, provide a parse
option
metalsmith.use(
metadata({
entries: {
nav: 'src/nav.yml',
featured: 'src/featured.yml'
},
parse: {
'.yml': customYamlParser,
'.csv': csvParse
}
})
)
In Windows a .json encoded with UTF8 (With Bom) return error of malformed data.
BOM is not stripped from the header of the UTF-8 file, if it exists.
Accurate bug description and solution here: http://stackoverflow.com/questions/24356713/node-js-readfile-error-with-utf8-encoded-file-on-windows
cc: @ianstormtaylor
I just started using metalsmith (and I really like it), but it seems like some of the plugins aren't being maintained. Do you guys need any help? Seems like people using this are running into some of the same issues I did.
i get the error:
Metalsmith · file "./config.yml" not found
in my metalsmith.json file i point to the config file as
"metalsmith-metadata": {
"config": "./config.yml"
},
I have the config.yml file in the root directory
I've been migrating the PlayCanvas Developer Site to the shiny new @metalsmith-prefixed NPM packages. Great to see these being updated! Is the metadata plugin going to be published to NPM as @metalsmith/metadata soon?
I was writing a question about this, but did some more research and figured it out. It wasn't obvious to me, so I'm assuming someone else might be struggle with it too.
If you want to use metadata (global or imported) in a Handlebars helper function, include options
as your last parameter. Then options.data.root
will be the global metadata object. If imported a key foo
with metalsmith-metadata
, you can access it as options.data.root.foo
.
Assume foo.json
is imported to foo
{
"bar": "Hello, World!"
}
helper, registered as 'foobar'
module.exports = function (parm, options) {
var foo = options.data.root.foo;
return(foo.bar);
Template
{{foobar}}
will produce output
Hello, World!
You can also access any file-level metadata in options.data.root
, for example if you have a title key in your document, options.data.root.title
You can get a sense of what's in options.data.root
by registering the following helper and calling it in a template.
module.exports = function (filename, options) {
var md = options.data.root;
for (i in md) {
console.log(i + " | " + md[i]);
}
};
This will log keys and values. Note that some values will be objects, but they should be obvious (partials
, knownHelpers
, etc.).
Metalsmith team
I'm not sure exactly where this information should go. It's related to using metalsmith-metadata, but also general to metalsmith (global metadata). It's focused on Handlebars helpers, but may apply to other templating engines. Tell me where you want this documented and I'll try to make it happen.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.