feat: add draft support

pull/6/head
Nicolas Doby 2022-11-25 15:50:48 +01:00
parent d11ca2e133
commit bef7af2d08
11 changed files with 57 additions and 13 deletions

View File

@ -70,19 +70,30 @@ module.exports = function(eleventyConfig) {
return Math.min.apply(null, numbers);
});
eleventyConfig.addFilter("filterDraft", articles => {
return articles.filter(article => !article.data.draft);
});
// Return all the tags used in a collection
eleventyConfig.addFilter("getAllTags", collection => {
let tagSet = new Set();
let tags = new Map();
for(let item of collection) {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
if (item.data.draft) {
continue;
}
(item.data.tags || []).forEach(tag => {
let number = tags.get(tag) || 0;
tags.set(tag, ++number);
});
}
return Array.from(tagSet).sort((a, b) => {
return a.localeCompare(b, undefined, {sensitivity: 'base'});
});
let sortedTags = new Map([...tags.entries()].sort((a, b) => b[1] - a[1]));
return Array.from(sortedTags.keys());
});
eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "nav", "article", "articles"].indexOf(tag) === -1);
// const filters = ["all", "nav", "article", "articles"];
// return new Map([...tags].filter(([k, _]) => filters.indexOf(k) === -1));
});
eleventyConfig.addFilter("readableAuthors", (authors) => {

View File

@ -21,10 +21,11 @@ templateClass: tmpl-post
<hr>
{%- if collections.articles %}
{%- set articles = collections.articles | filterDraft %}
{%- if articles %}
{# these filters are locale-aware in 2.0.0-canary.14 #}
{%- set previousArticle = collections.articles | getPreviousCollectionItem %}
{%- set nextArticle = collections.articles | getNextCollectionItem %}
{%- set previousArticle = articles | getPreviousCollectionItem %}
{%- set nextArticle = articles | getNextCollectionItem %}
{%- if nextArticle or previousArticle %}
<nav class="post-nav">
<ul>

View File

@ -9,7 +9,7 @@ eleventyNavigation:
<nav>
{% include "tagslist.njk" %}
</nav>
{% set articlesList = collections.articles %}
{% set articlesList = collections.articles | filterDraft %}
{% include "articlesList.njk" %}
</div>
<aside class="right-side">

View File

@ -8,6 +8,7 @@ tags:
- ACV
authors:
- Margaux Escande
draft: false
layout: article.njk
---
À ce jour, le numérique a plus d'impacts environnementaux que l'aviation civile et ses impacts continuent d'augmenter.

View File

@ -9,6 +9,7 @@ tags:
- écoconception
authors:
- Margaux Escande
draft: false
layout: article.njk
---

View File

@ -9,6 +9,7 @@ authors:
- Anne Faubry
- Aurélie Baton
- Nicolas Doby
draft: false
layout: article.njk
---
En 2022, nous avons conçu et développé le site ["Celtique ? L'expo"](https://www.exposition-celtique.bzh) dans une

View File

@ -9,6 +9,7 @@ tags:
- ACV
authors:
- Anthony Lecerf
draft: false
layout: article.njk
---
Le numérique est au cœur de notre quotidien et bouleverse nos modes de vie et de travail. Il a également des effets

View File

@ -0,0 +1,28 @@
---
title: "Test"
description: "test"
date: 2022-11-25
tags:
- test
- test2
- test3
authors:
- John Doe
draft: true
layout: article.njk
---
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus deleniti eius, eveniet fugit magni provident
vel? Corporis deserunt doloribus ducimus hic iusto nemo neque perspiciatis qui sit totam! Culpa, saepe!
Accusamus consectetur consequatur cupiditate est neque nisi pariatur possimus quisquam quod ratione. Atque dolorem
eius excepturi explicabo, illo, inventore ipsam laborum maxime molestias nisi omnis possimus sequi temporibus ut vero.
Accusantium aspernatur beatae commodi corporis, delectus dolore earum et explicabo illo illum ipsa ipsam iste magni
maiores minus neque omnis quis rem rerum sapiente sed ullam unde velit vitae voluptatum?
Atque, deserunt enim itaque laborum libero magnam minus pariatur quam, reiciendis repellat suscipit velit. Ad
aliquam debitis dolores fuga harum libero minus quaerat quam sequi velit! Recusandae rem, voluptatibus. Possimus?
Amet id itaque numquam obcaecati rem! Mollitia nostrum numquam quod. Aperiam assumenda, delectus dolor fuga fugiat,
iste maxime neque pariatur porro provident quaerat vitae voluptas? Dolorem quia quo tempore voluptatem.

View File

@ -8,13 +8,13 @@ permalink: /blog/feed/feed.xml
<subtitle>{{ metadata.description }}</subtitle>
<link href="{{ permalink | htmlBaseUrl(metadata.url) }}" rel="self"/>
<link href="{{ metadata.url | addPathPrefixToFullUrl }}"/>
<updated>{{ collections.articles | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<updated>{{ collections.articles | filterDraft | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<id>{{ metadata.url }}</id>
<author>
<name>{{ metadata.author.name }}</name>
<email>{{ metadata.author.email }}</email>
</author>
{%- for article in collections.articles | reverse %}
{%- for article in collections.articles | filterDraft | reverse %}
{% set absolutePostUrl %}{{ article.url | htmlBaseUrl(metadata.url) }}{% endset %}
<entry>
<title>{{ article.data.title }}</title>

View File

@ -14,7 +14,7 @@ permalink: /blog/feed/feed.json
"url": "{{ metadata.author.url }}"
},
"items": [
{%- for article in collections.articles | reverse %}
{%- for article in collections.articles | filterDraft | reverse %}
{%- set absoluteArticleUrl = article.url | htmlBaseUrl(metadata.url) %}
{
"id": "{{ absoluteArticleUrl }}",

View File

@ -10,7 +10,7 @@ eleventyNavigation:
<nav>
{% include "tagslist.njk" %}
</nav>
{% set articlesList = collections.articles | head(-5) %}
{% set articlesList = collections.articles | filterDraft | head(-5) %}
{% include "articlesList.njk" %}
</div>
<aside class="right-side">