stephanmax / metalsmith-slug Goto Github PK
View Code? Open in Web Editor NEWAdd a slug property to targeted files in Metalsmith
Add a slug property to targeted files in Metalsmith
Hi @nsonnad, I am still using this wonderful Metalsmith plugin and would love to see its dependencies being updated. I notices you haven’t updated the repo in a while—do you mind me asking if you would be willing to transfer the repo to me so I can maintain it?
Thanks in advance!
It would be nice the possibility to set the slug
property manually in a single file. That way, the value of slug
on this file may not change.
Let's say we have 3 files: one.md
, two.md
and three.md
, and three.md
has the slug
property set manually with a different value:
one.md:
---
title: One Pig
---
Contents in One...
two.md:
---
title: Two Pigs
---
Contents in Two...
three.md: (with slug
set manually)
---
title: Three Pigs
slug: how-many-pigs-i-want-here
---
Contents in Three...
The output of processed files should be:
{
'one.md': {title: 'One Pig', slug: 'one-pig'},
'two.md': {title: 'Two Pigs', slug: 'two-pigs'},
'three.md': {title: 'Three Pigs', slug: 'how-many-pigs-i-want-here'},
}
What do you think @nsonnad? I can submit a PR for this feature today if you agree. =)
Here 0.5.0: https://www.npmjs.com/package/metalsmith-slug
For reference: https://docs.npmjs.com/getting-started/publishing-npm-packages
In Metalsmith 1.0 there was an API change for source()
so that if no option is given it returns the absolute path to the src
directory. So, when calling matchGlobArray
all the files fail to pass the test and slug()
doesn't do anything. Example input for matchGlobArray
when using default patterns
value:
file: articles/20150416-ror_ca.md
pattern: /Users/doup/Code/gra-web-new/src/** (from ms.source())
---
minimatch result: false
A workaround is to pass the patterns
option to slug()
, e.g:
.use(slug({ patterns: ['*.md'] }))
First, thanks for this plugin which I find really helpful. It's really nice to have fine-grained control over URLs. The only issue I had is that I wanted the final url to be \example\slug-text-here\
rather than \example\slug-text-here.html
.
With a quick adjustment to line 23 where the filename is set, I was able to create folders with index.html files to account for that:
var slugFilename = path.join(currPath, newSlug, 'index' + currExt);
This is a similar methodology to metalsmith-permalinks. The difference is that plugin does not have a manual override allowing you to set the link in the frontmatter the way slug does.
Would be great to see this functionality in the official plugin as a configuration option.
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.