-
-
Notifications
You must be signed in to change notification settings - Fork 43
Add blog posts to website #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Keep in mind that since the web version releases are tied to the bashunit releases, to add new articles a release would be needed. This has a solution since the articles could be read from main branch and rendered with the latest branch code 🌈 , but adding this behavior would add too much complexity to the PR. Since the blog was in a functional state I decided to make the PR and will add this functionality later on. |
| @@ -0,0 +1,19 @@ | |||
| --- | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file serves as a template for the posts we create, it has a frontmatter section that need to be filled out besides the post itself.
This metadata must be correctly filled out, as these are used by the index to render the cards that allow access to each post.
- date: ISO format, time is not necessary (unless we want to display them in the publications)
- title: Post's title
- description: Introduction to the post, usually the first paragraph of it
- coverUrl: Cover image of the post
- coverAlt: Description of the post's cover image
|
|
||
| aside: false | ||
| --- | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid having to repeat the texts written above, these lines allow to render them again within the article itself, the idea is to follow a standard format in all our articles so these lines should not be modified, but can be modified whenever an article requires it.
|
|
||
| <img :src="$frontmatter.coverUrl" :alt="$frontmatter.coverAlt"> | ||
|
|
||
| Post content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the article will go here, written in md format.
| --- | ||
| aside: false | ||
| --- | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is the blog index, displaying a list of posts drawing from the metadata provided with frontmatter.
There's a filter to prevent listing itself and the example template.
docs/posts/posts.data.ts
Outdated
| @@ -0,0 +1,3 @@ | |||
| import { createContentLoader } from 'vitepress' | |||
|
|
|||
| export default createContentLoader('posts/*.md', ) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file obtains the metadata from the posts and passes it to the index, this implementation is a very simple builtin provided by VitePress and is sufficient for this first milestone.
If we wanted to read the posts from the main branch with the build from the latest branch, this implementation would need to be modified to use the GitHub API, for now and for simplicity, I've decided to leave it as is.
| app.config.globalProperties.$formatDate = (date: string) => { | ||
| return DateTime.fromISO(date) | ||
| .toLocaleString(DateTime.DATE_HUGE, { locale: 'en-US' }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this small helper with Luxon to format the post dates from ISO to a standard format, so we won't have to do it manually.
|
|
||
| srcExclude: [ | ||
| 'posts/0000-00-00-template.md' | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template is excluded so it is not accessible in the final build.
| import PostCard from './PostCard.vue' | ||
|
|
||
| const posts = data.filter((post) => post.url != '/posts/' && post.url != '/posts/0000-00-00-template') | ||
| .sort((postA, postB) => postA.url < postB.url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL of the posts (the name of the md files) is what is used to order them. I could have used the date metadata, but this way we force ourselves to add the date to the name as well and thus have the same order on our operating systems.
|
I've replace the use of Luxon with the Great work @Tito-Kati, the blog section looks amazing 🚀 |
Chemaclass
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this initial setup for our internal bashunit blog! Kudos, @Tito-Kati 👏🏼
fabriziofs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
📚 Description
I've modified the bashunit website to host a blog in addition to the documentation.
Some screenshots to see the result:


I also add some comments to the code to better explain the functionality.
🔖 Changes
✅ To-do list
CHANGELOG.mdto reflect the new feature or fix