Skip to content

Commit

Permalink
docs: blog tags
Browse files Browse the repository at this point in the history
  • Loading branch information
gustaveWPM committed Mar 6, 2024
1 parent 60e0ee8 commit 3f8e771
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions doc/blog/05.tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Blog tags

Let's explore the tags feature!

---

## The blog documents front-matter

Let's create a dummy blog document.

```markdown
---
title: Note
metadescription: Meta description
description: Description
date: 2019-08-14 21:00
---

Hello world!
```

By default, this document will not have any tag.

You can tweak it to enable the tags feature just like so:

```markdown
---
tags: ['hello', 'world']
title: Note
metadescription: Meta description
description: Description
date: 2019-08-14 21:00
---

Hello world!
```

You can also write it as follows:

```markdown
---
tags:
- hello
- world
title: Note
metadescription: Meta description
description: Description
date: 2019-08-14 21:00
---

Hello world!
```

Because of a weird Contentlayer bug, keep the `tags` field at the top of the document properties. Otherwise, it could break its parsing on Windows.

**Don't forget to describe the tags for your blog post in all its different languages.**

## The Blog Tags Config file

It is possible to manage the blog tags thanks to the [_blog tags config file_.](/interop/config/contentlayer/blog/blogTags.ts)

Let:

```ts
// interop/config/contentlayer/blog/blogTags.ts
const _blogTagOptions = [] as const satisfies string[];
```

Become:

```ts
// interop/config/contentlayer/blog/blogTags.ts
const _blogTagOptions = ['hello', 'world'] as const satisfies string[]; // * ... Added 'hello' and 'world' tags
```

Then, you'll notice a new error in your [locale files.](/src/i18n/locales)

For instance:

> Type '{}' is missing the following properties from type 'MakeHomogeneousValuesObjType<Record<"hello" | "world">, string>': hello, world
This is because your [i18n schema file](/src/i18n/locales/schema.ts) injects i18n constraints to force you to declare the translations of your blog
tags:

```ts
// src/i18n/locales/schema.ts
'blog-tags': blogTagOptionsVocabSchema
```

Let's fix it!

Turn this:

```ts
// src/i18n/locales/fr.ts
'blog-tags': {}
```

Into this:

```ts
// src/i18n/locales/fr.ts
'blog-tags': {
hello: 'Bonjour',
world: 'Monde'
}
```

Adapt all your locales like this, then, go to your blog category page.

---

<p align="center"><img src="./Assets/05.tags/final-result-en.png" alt="Result (en)"/></p>
<p align="center"><img src="./Assets/05.tags/final-result-fr.png" alt="Result (fr)"/></p>

Congrats!
You made it!
Binary file added doc/blog/Assets/05.tags/final-result-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/blog/Assets/05.tags/final-result-fr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3f8e771

Please sign in to comment.