Skip to content

Commit

Permalink
Parse article title Markdown in articles index
Browse files Browse the repository at this point in the history
  • Loading branch information
meduzen committed Nov 11, 2023
1 parent 4adb107 commit 590f6e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vitepress/.vitepress/theme/ArticlesIndexClient.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const dateFormatter = new Intl.DateTimeFormat('en-GB', {

<template>
<template v-for="({ excerpt, frontmatter: { title, publishedAt, tags }, url }) in data">
<h2><a :href="url" v-html="title"/></h2>

<h2><a :href="url">{{ title }}</a></h2>
<time :datetime="datetime(new Date(publishedAt), 'year')">{{ dateFormatter.format(publishedAt) }}</time>

<tags v-if="tags" :tags="tags" />
Expand Down
10 changes: 6 additions & 4 deletions vitepress/articles.data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ export default createContentLoader('articles/*.md', {
articles
.forEach(article => {

// parse Markdown in title
article.frontmatter.title = mdRenderer.render(article.frontmatter.title)

// convert coma-separated list of tags to array
article.frontmatter.tags = (article.frontmatter.tags?.split(',') ?? []).map(tag => tag.trim())

// convert Markdown excerpt to HTML
if ('excerpt' in article.frontmatter) {
article.frontmatter.excerpt = mdRenderer.render(article.frontmatter.excerpt)
}


// convert coma-separated list of tags to array
article.frontmatter.tags = (article.frontmatter.tags?.split(',') ?? []).map(tag => tag.trim())
})

return articles
Expand Down

0 comments on commit 590f6e0

Please sign in to comment.