-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit: - Adds a tags collection - Adds a slugify package - not the same one 11ty uses, because that package is incompatible with CommonJS inclusion, and we'd have to switch everything to ESM. - Removes the unused tagList collection - Moves all collection creation functions into config/collections.js - Creates tag pages - Fixes tag index page, and changes it from a layout to a page - Refactors featured topics/tags data - now it looks up the tag name from the slug, instead of hardcoding a duplicate name
- Loading branch information
Showing
12 changed files
with
178 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
blog: | ||
tags: | ||
- acquisition-services | ||
- agile | ||
- culture-change | ||
- how-we-work | ||
- lessons-learned | ||
case_studies: | ||
- agency: U.S. Forest Service | ||
- agency: Alaska Department of Health and Social Services | ||
- agency: Department of Justice | ||
- agency: U.S. Tax Court | ||
- agency: Department of the Treasury | ||
- agency: Department of State |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<a href="{{ "/blog/" | url }}" class="display-flex flex-align-center"><span class="usa-sr-only">Back to</span>{%- include "svg/icons/arrow-left.svg" -%}<span class="margin-left-05">18F Blog </span> </a> | ||
{% assign post_count = tag.data.posts | size %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// smell: This is not the slugify library used by 11ty | ||
// However, that library requires ESM and this project is CommonJS. | ||
// The best thing to do would be to import the slugify filter, but I'm not quite | ||
// sure how to do that from this separate file — perhaps dependency injection | ||
// in .eleventy.js? | ||
const slugify = require('slugify'); | ||
|
||
slugify.extend({'.': '-'}) | ||
|
||
const postsCollection = (collection) => collection.getFilteredByGlob('content/posts/*.md'); | ||
const servicesCollection = (collection) => collection.getFilteredByGlob('content/pages/projects/services/*.md'); | ||
|
||
// Create a collection of all tags across all posts | ||
// Each tag has a `name` property, as well as a `posts` array with all the posts with that tag | ||
const tagsCollection = (collection) => { | ||
const tagMap = new Map(); | ||
|
||
collection.getAll().forEach((post) => { | ||
(post.data.tags || []).forEach((tag) => { | ||
if (!tagMap.has(tag)) { | ||
tagMap.set(tag, []) | ||
}; | ||
tagMap.get(tag).push(post) | ||
}); | ||
}); | ||
|
||
// Alpha-sorts by key, so that we don't have to do any sorting to get the tag index | ||
// displaying tags in alphabetical order | ||
const sortedMap = new Map([...tagMap].sort((a, b) => String(a[0]).localeCompare(b[0]))) | ||
|
||
// Creates the data object with the right keys | ||
const tags = [] | ||
sortedMap.forEach((posts, name) => { | ||
const slug = slugify(name, { lower: true, strict: true }); | ||
tags.push({ | ||
data: { | ||
name, | ||
posts, | ||
posts_count: posts.length | ||
}, | ||
date: null, | ||
fileSlug: slug, | ||
inputPath: null, | ||
url: `/tags/${ slug }/`, | ||
}) | ||
}) | ||
return tags; | ||
// I commented this out — it's not clear what it's doing and it doesn't seem important. | ||
// return filterTagList([...tagSet]); | ||
}; | ||
|
||
module.exports = { | ||
postsCollection, | ||
servicesCollection, | ||
tagsCollection, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
--- | ||
title: Tags | ||
layout: tag-index | ||
layout: styled-container | ||
permalink: /tags/ | ||
--- | ||
|
||
<p>Click through to read our posts about the following topics:</p> | ||
|
||
{% for tag in collections.tags %} | ||
<p> | ||
<a href="{{ tag.url | url }}/" >{{ tag.data.name }}</a> | ||
— {{ tag.data.posts_count }} | ||
</p> | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
pagination: | ||
data: collections.tags | ||
size: 1 | ||
alias: tag | ||
permalink: "{{ tag.url }}" | ||
layout: "tag-results" | ||
--- |
Oops, something went wrong.