Skip to content

Commit

Permalink
Add RSS feed to <head> and in navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
meduzen committed Nov 11, 2023
1 parent f1ae8bc commit df5174f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
9 changes: 7 additions & 2 deletions vitepress/.vitepress/config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { defineConfig } from 'vitepress'
import { rss } from './rss.mjs'

const APP_URL = `https://blog.mehdi.cc`
const APP_TITLE = 'Mehdi’s Notes'

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: 'Mehdi’s Notes',
title: APP_TITLE,
description: 'Content for your web-enthusiast brain, by Mehdi Merah.',
lang: 'en',
cleanUrls: true, // https://vitepress.dev/guide/routing#generating-clean-url
Expand All @@ -12,7 +15,8 @@ export default defineConfig({
buildEnd: rss,

head: [
['meta', { name:'color-scheme', content:'dark light only' }]
['meta', { name: 'color-scheme', content: 'dark light only' }],
['link', { rel: 'alternate', type: 'application/rss+xml', title: APP_TITLE, href: `${APP_URL}/feed.rss` }]
],

themeConfig: {
Expand All @@ -22,6 +26,7 @@ export default defineConfig({
{ text: 'Articles', link: '/articles' },
{ text: 'Notes', link: '/notes' },
{ text: 'About', link: '/about' },
{ text: 'RSS', link: '/feed.rss' },
],

// sidebar: [
Expand Down
12 changes: 6 additions & 6 deletions vitepress/.vitepress/rss.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createContentLoader } from 'vitepress'
import { comparePublicationDate, isPublished } from './utils/frontmatter.mjs'

/** @todo: should come from .env */
const baseUrl = `https://blog.mehdi.cc`
const APP_URL = `https://blog.mehdi.cc`

/**
* @param {import('vitepress').SiteConfig} config
Expand All @@ -17,14 +17,14 @@ export async function rss(config) {
*/
const feed = new Feed({
docs: 'https://www.rssboard.org/rss-specification',
link: baseUrl + 'link',
link: APP_URL + 'link',
title: config.site.title,
description: config.site.description,
language: config.site.lang,
// image: 'https://blog.mehdi.cc/file.png',
// favicon: `${baseUrl}/favicon.ico`,
// favicon: `${APP_URL}/favicon.ico`,
copyright: 'Copyright © 2023-present, Mehdi Merah',
feed: `${baseUrl}/feed.rss`,
feed: `${APP_URL}/feed.rss`,
ttl: 2880, // 1 day,
});

Expand All @@ -34,8 +34,8 @@ export async function rss(config) {
.forEach(({ url, excerpt, frontmatter, html }) =>
feed.addItem({
title: frontmatter.title,
id: `${baseUrl}${url}`,
link: `${baseUrl}${url}`,
id: `${APP_URL}${url}`,
link: `${APP_URL}${url}`,
description: frontmatter.description || excerpt,
content: html,
date: frontmatter.publishedAt,
Expand Down
8 changes: 4 additions & 4 deletions vitepress/.vitepress/theme/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import './custom.css'
import DefaultTheme from 'vitepress/theme'
import NotesIndex from './NotesIndex.vue'
// import NotesIndex from './NotesIndex.vue'

export default {
extends: DefaultTheme,
enhanceApp({ app }) {
app.component('notes-index', NotesIndex)
}
// enhanceApp({ app }) {
// app.component('notes-index', NotesIndex)
// }
}

0 comments on commit df5174f

Please sign in to comment.