Skip to content

Commit

Permalink
adding tags functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
holger1411 committed Jul 14, 2021
1 parent 1ffc229 commit b05a527
Show file tree
Hide file tree
Showing 19 changed files with 313 additions and 63 deletions.
31 changes: 28 additions & 3 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
const {
DateTime
} = require("luxon");
const { DateTime } = require("luxon");
const navigationPlugin = require('@11ty/eleventy-navigation')
const rssPlugin = require('@11ty/eleventy-plugin-rss')

module.exports = function(eleventyConfig) {


function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav"].indexOf(tag) === -1);
}
eleventyConfig.setDataDeepMerge(true);

function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
}

eleventyConfig.addFilter("filterTagList", filterTagList)

// Create an array of all tags
eleventyConfig.addCollection("tagList", function(collection) {
let tagSet = new Set();
collection.getAll().forEach(item => {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
});

return filterTagList([...tagSet]);
});


// Add a filter using the Config API
eleventyConfig.addWatchTarget("./src/scss/");
eleventyConfig.setBrowserSyncConfig({
reloadDelay: 400
});

eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj, {
zone: 'utc'
Expand Down
166 changes: 166 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: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
},
"author": "Holger Koenemann",
"devDependencies": {
"@11ty/eleventy-navigation": "^0.3.2",
"@11ty/eleventy-plugin-rss": "^1.1.1",
"gulp-html-replace": "^1.6.2",
"gulp-purgecss": "^4.0.3",
"node-sass": "^6.0.1",
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/_includes/layouts/blog.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

{% include 'snippets/navbar.njk' %}

<main class="container py-vh-5 pb-0">
<main class="container py-5">
{% include 'snippets/maincontent.njk' %}
</main>

<div class="container py-vh-5">
<div class="container">
{% include 'snippets/postloop.njk' %}
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/_includes/layouts/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{% include 'snippets/navbar.njk' %}

<main class="container py-5">
<main class="container">
{% include 'snippets/postcontent.njk' %}
</main>

Expand Down
2 changes: 1 addition & 1 deletion src/_includes/snippets/maincontent.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="row d-flex justify-content-center">
<div class="col-12 col-lg-10 col-xl-8">
<div class="col-12">
<header>
<h1 class="display-1">{{ title }}</h1>
</header>
Expand Down
8 changes: 7 additions & 1 deletion src/_includes/snippets/postcontent.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="row d-flex justify-content-center">
<div class="col-12 col-lg-10 col-xl-8">
<div class="col-12">
<article>
<header class="border-bottom pb-4 mb-4">
<h1 class="display-1">{{ title }}</h1>
Expand All @@ -13,6 +13,12 @@
<p>Published
<time datetime="{{ page.date | htmlDateString }}">{{ page.date | readableDate }}</time>
</p>
<p>
{% for tag in post.data.tags | filterTagList %}
{% set tagUrl %}/tags/{{ tag | slug }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{% endfor %}
</p>
{% endblock %}
</header>
<p class="lead">
Expand Down
36 changes: 17 additions & 19 deletions src/_includes/snippets/postloop.njk
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
<div class="row d-flex justify-content-center">
<div class="col-12 col-lg-10 col-xl-8">
<div class="col-12">
{%- for post in posts %}
<div class=" border-top py-5">
<h2>{{ post.data.title}}</h2>
<time datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time>
<p>{{ post.data.intro }}</p>
<a href="{{ post.url | url }}" class="link-fancy">Read more...</a>
</div>
<div class=" border-top py-5">
<h2>{{ post.data.title}}</h2>
<time datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time>
{% for tag in post.data.tags | filterTagList %}
{% set tagUrl %}/tags/{{ tag | slug }}/{% endset %}
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a>
{% endfor %}
<p>{{ post.data.summary }}</p>
<a href="{{ post.url | url }}" class="link-fancy">Read more...</a>
</div>
{% endfor %}
</div>
</div>


<div class="row d-flex justify-content-center">
<div class="col-12 col-lg-10 col-xl-8">
<div class="col-12">
<div class="row d-flex justify-content-between">
<div class="col">
{% if pagination.href.previous %}
<a href="{{pagination.href.previous}}"><< Previous Page</a>
{% endif %}
</div>
<div class="col text-end">
{% if pagination.href.next %}
<a href="{{pagination.href.next}}">Next Page >></a>
{% endif %}
<div class="col">
{% if pagination.href.previous %}
<a href="{{pagination.href.previous}}"><< Previous Page</a> {% endif %} </div> <div class="col text-end"> {% if pagination.href.next %} <a href="{{pagination.href.next}}">Next Page >></a>
{% endif %}
</div>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion src/blog.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: layouts/blog.njk
title: My personal blog
pagination:
data: collections.posts
data: collections.post
size: 3
reverse: true
alias: posts
Expand Down
Loading

1 comment on commit b05a527

@vercel
Copy link

@vercel vercel bot commented on b05a527 Jul 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.