Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
eleventy-nbsp-filter
Advanced tools
Filter for Eleventy to replace spaces between words with characters
🛸 Filter for Eleventy to replace spaces between words with characters.
Sometimes it happens that titles move to a next line leaving one short word alone, one solution is to add a
entity instead of a normal space character, but doing this on your content files might not be ideal since then you need to escape that character in other places you consume that data.
I found myself polluting my titles with this character to then remove it, what if I just had a filter where given a title and a certain safe length of characters this gets done automatically, preserving the title as it is? This is why eleventy-nbsp-filter
exists.
# npm
npm i eleventy-nbsp-filter --save
# yarn
yarn add eleventy-nbsp-filter
Include the filter in your Eleventy project.
// .eleventy.js
const nbspFilter = require('eleventy-nbsp-filter')
const numberOfWordsToJoin = 2
const maxLength = 10
module.exports = function(eleventyConfig) {
eleventyConfig.addFilter('nbsp', nbspFilter(numberOfWordsToJoin, maxLength))
}
The filter will add the last two words of a tet value, only if they don't pass the amount of ten characters together. You can pass any configuration that adapts to your needs.
<h1>{{ page.title | nbsp }}</h1>
And that's it! Keep reading to understand why you need to pass some numbers to the filter.
The filter will require you to define how many words you want to join and the maximum number of characters which is safe to join, this is in order to avoid text to overflow the viewport.
So, let's say you add a filter with the config exactly like the example above.
If the filter receives this text, There is a place where the sidewalk ends
it will bail out on adding the
character because we said we wanted 2
words to be joint, but those together are 12
characters and we passed 10
as the maximum length.
Now if we pass this text, We'll walk with a walk that is measured and slow
, then the result will be We'll walk with a walk that is measured and slow
because the last two words sum to 7
characters, then the filter acts.
The config is an extra weight-lifting you need to do, but provides a safer and more adaptable distribution of itself to better adjust your needs regarding this super nitpicky action.
Text excerpts are taken from Shel Silverstein's poem "Where the Sidewalk Ends".
To contribute Node.js and yarn are required.
Before commit make sure to follow conventional commits specification and check all tests pass by running yarn test
.
FAQs
Filter for Eleventy to replace spaces between words with characters
The npm package eleventy-nbsp-filter receives a total of 5 weekly downloads. As such, eleventy-nbsp-filter popularity was classified as not popular.
We found that eleventy-nbsp-filter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.