Skip to content

Conversation

@antonio-gg-dev
Copy link
Member

@antonio-gg-dev antonio-gg-dev commented Oct 12, 2023

📚 Description

I've modified the bashunit website to host a blog in addition to the documentation.

Some screenshots to see the result:
imagen
imagen

I also add some comments to the code to better explain the functionality.

🔖 Changes

  • Added two buttons to the top navigation that serve as quick access to the documentation and the blog.
    • These buttons remain highlighted to indicate to the user which section they are in.
  • Added a button to the blog on the home page.
  • Added directory where all blog posts will be hosted.
    • All pages within this directory will not have a sidebar.
    • Added index page of the posts published on the blog.

✅ To-do list

  • Make sure that all the pipeline passes
  • Make sure you have updated the documentation to reflect the changes or new features
  • Make sure to update the CHANGELOG.md to reflect the new feature or fix

@antonio-gg-dev antonio-gg-dev added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 12, 2023
@antonio-gg-dev antonio-gg-dev self-assigned this Oct 12, 2023
@antonio-gg-dev antonio-gg-dev marked this pull request as ready for review October 12, 2023 16:04
@antonio-gg-dev antonio-gg-dev changed the title Add posts to docs Add blog posts to website Oct 12, 2023
@antonio-gg-dev
Copy link
Member Author

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 @@
---
Copy link
Member Author

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
---

Copy link
Member Author

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
Copy link
Member Author

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
---

Copy link
Member Author

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.

@@ -0,0 +1,3 @@
import { createContentLoader } from 'vitepress'

export default createContentLoader('posts/*.md', )
Copy link
Member Author

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' })
}
Copy link
Member Author

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'
]
Copy link
Member Author

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)
Copy link
Member Author

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.

@fabriziofs
Copy link
Collaborator

I've replace the use of Luxon with the Intl built-in object. But i don't know why the TS compiler show an error with the dateStyle key, so I put a @ts-ignore above that line 🤒

Great work @Tito-Kati, the blog section looks amazing 🚀

Copy link
Member

@Chemaclass Chemaclass left a 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 👏🏼

Copy link
Collaborator

@fabriziofs fabriziofs left a comment

Choose a reason for hiding this comment

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

🚀

@Chemaclass Chemaclass merged commit 28b17d1 into main Oct 14, 2023
@Chemaclass Chemaclass deleted the add-posts-to-docs branch October 14, 2023 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants