-
Notifications
You must be signed in to change notification settings - Fork 8
update: prototype
– serializedTitle, improving logic, and little revamp
#210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
splicing year and title, where year becomes 2 last digits, and title is first letter of each words
✅ Deploy Preview for emptywork ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
prototype
– serializedTitleprototype
– serializedTitle, improving logic, and little revamp
eleventyConfig.addFilter('cutText', (string, size) => { | ||
return string.split('-').splice(0, size).join('-') | ||
}) | ||
|
||
eleventyConfig.addFilter('serializeTitle', (string, yearSplice = 2) => { | ||
const titleParts = string.split('-') | ||
const [year, ...title] = titleParts | ||
const titleInitials = title.map(title => title.split('')[0]).join('') | ||
const yearSuffix = year.slice(-yearSplice) | ||
|
||
return `${yearSuffix}-${titleInitials}` | ||
}) | ||
|
||
eleventyConfig.addFilter('breakLine', (string, cutAt = 3, maxSize = 30) => { | ||
const titleWords = string.split(' ') | ||
const titleLength = string.length | ||
const titlePreview = titleWords.slice(0, cutAt).join(" ") | ||
const titleRemaining = titleWords.slice(cutAt).join(" ") | ||
|
||
const hasTitleRemaining = !!titleRemaining | ||
const formattedTitleWithBreak = hasTitleRemaining ? `${titlePreview}<br/>${titleRemaining}` : titlePreview | ||
|
||
const returnTitle = titleLength <= maxSize || !hasTitleRemaining ? string : formattedTitleWithBreak | ||
return returnTitle | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not sure the naming of the functions, but for now the naming is sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need to review back the naming for .eleventy filters name.
No description provided.