Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ module.exports = function(eleventyConfig) {
);
});

eleventyConfig.addFilter("stripForSearch", function(content) {
return content
.replace(/<[^>]*>/g, '')
.replace(/\s+/g, ' ')
.trim();
});

eleventyConfig.addFilter("searchableTags", function(str) {
let tags;
let match = str && str.match(tagRegex);
Expand Down Expand Up @@ -651,6 +658,22 @@ module.exports = function(eleventyConfig) {
return content;
});

eleventyConfig.addTransform("jsonMinifier", async (content, outputPath) => {
if (
(process.env.NODE_ENV === "production" || process.env.ELEVENTY_ENV === "prod") &&
outputPath &&
outputPath.endsWith(".json")
) {
try {
return JSON.stringify(JSON.parse(content));
} catch {
// If the JSON minifying fails for some reason due to malformed JSON, just return the content as is.
return content;
}
}
return content;
});

eleventyConfig.addPassthroughCopy("src/site/img");
eleventyConfig.addPassthroughCopy("src/site/scripts");
eleventyConfig.addPassthroughCopy("src/site/styles/_theme.*.css");
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/site/search-index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ eleventyExcludeFromCollections: true
"title": {% if post.data.title %}{{post.data.title | jsonify | safe }}{% else %}{{post.fileSlug | jsonify | safe }}{% endif %},
"date":"{{ post.date }}",
"url":"{{ post.url }}",
"content": {{ post.templateContent | striptags(true) | link | jsonify | safe }},
"content": {{ post.templateContent | link | stripForSearch | jsonify | safe }},
"tags": [{{post.templateContent | link | searchableTags | safe }} {% if post.data.tags %}{% for tag in post.data.tags %}"{{tag|validJson}}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %}]
}{% if not loop.last %},{% endif %}
{% endfor %}]
Loading