rss feed
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { defineConfig } from "vitepress";
|
||||
import UnoCSS from "unocss/vite";
|
||||
import { presetUno, presetAttributify, presetIcons } from "unocss";
|
||||
import consola from "consola";
|
||||
import { commitRef, feedback, meta, socials } from "./constants";
|
||||
import { generateImages, generateMeta } from "./hooks";
|
||||
import { generateImages, generateMeta, generateFeed } from "./hooks";
|
||||
import { toggleStarredPlugin } from "./markdown/toggleStarred";
|
||||
import { base64DecodePlugin } from "./markdown/base64";
|
||||
|
||||
@@ -35,7 +36,9 @@ export default defineConfig({
|
||||
],
|
||||
transformHead: async (context) => generateMeta(context, meta.hostname),
|
||||
buildEnd: async (context) => {
|
||||
generateImages(context);
|
||||
generateImages(context)
|
||||
.then(() => generateFeed(context))
|
||||
.finally(() => consola.success("Success!"));
|
||||
},
|
||||
vite: {
|
||||
plugins: [
|
||||
|
@@ -3,7 +3,7 @@ import type { DefaultTheme } from "vitepress";
|
||||
export const meta = {
|
||||
name: "FreeMediaHeckYeah",
|
||||
description: "The largest collection of free stuff on the internet!",
|
||||
hostname: "https://fmhy.pages.dev",
|
||||
hostname: "https://fmhy.net",
|
||||
keywords: ["stream", "movies", "gaming", "reading", "anime"],
|
||||
};
|
||||
|
||||
|
@@ -4,3 +4,5 @@
|
||||
|
||||
export * from "./meta";
|
||||
export * from "./opengraph";
|
||||
export * from "./rss";
|
||||
export * from "./satoriConfig";
|
||||
|
@@ -5,6 +5,7 @@ import { createContentLoader } from "vitepress";
|
||||
import type { ContentData, SiteConfig } from "vitepress";
|
||||
import { type SatoriOptions, satoriVue } from "x-satori/vue";
|
||||
import { renderAsync } from "@resvg/resvg-js";
|
||||
import consola from "consola";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const __fonts = resolve(__dirname, "../fonts");
|
||||
@@ -48,6 +49,7 @@ export async function generateImages(config: SiteConfig): Promise<void> {
|
||||
fonts,
|
||||
});
|
||||
}
|
||||
return consola.info("Generated opengraph images.");
|
||||
}
|
||||
|
||||
interface GenerateImagesOptions {
|
||||
@@ -90,5 +92,5 @@ async function generateImage({
|
||||
|
||||
await mkdir(outputFolder, { recursive: true });
|
||||
|
||||
return await writeFile(outputFile, render.asPng());
|
||||
await writeFile(outputFile, render.asPng());
|
||||
}
|
||||
|
42
.vitepress/hooks/rss.ts
Normal file
42
.vitepress/hooks/rss.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import path from "node:path";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { Feed } from "feed";
|
||||
import { createContentLoader, type ContentData, type SiteConfig } from "vitepress";
|
||||
import consola from "consola";
|
||||
import { meta } from "../constants";
|
||||
|
||||
export async function generateFeed(config: SiteConfig): Promise<void> {
|
||||
const feed: Feed = new Feed({
|
||||
id: meta.hostname,
|
||||
link: meta.hostname,
|
||||
title: `FMHY blog`,
|
||||
description: meta.description,
|
||||
language: "en-US",
|
||||
image: "https://github.com/fmhy.png",
|
||||
favicon: `${meta.hostname}/favicon.ico`,
|
||||
copyright: `Copyright (c) 2023-present FMHY`,
|
||||
});
|
||||
|
||||
const posts: ContentData[] = await createContentLoader("posts/*.md", {
|
||||
excerpt: true,
|
||||
render: true,
|
||||
transform: (rawData) => {
|
||||
return rawData.sort((a, b) => {
|
||||
return Number(new Date(b.frontmatter.date)) - Number(new Date(a.frontmatter.date));
|
||||
});
|
||||
},
|
||||
}).load();
|
||||
|
||||
for (const { url, frontmatter, html } of posts) {
|
||||
feed.addItem({
|
||||
title: frontmatter.title as string,
|
||||
id: `${meta.hostname}${url.replace(/\/\d+\./, "/")}`,
|
||||
link: `${meta.hostname}${url.replace(/\/\d+\./, "/")}`,
|
||||
date: frontmatter.date,
|
||||
content: html!,
|
||||
});
|
||||
}
|
||||
|
||||
writeFileSync(path.join(config.outDir, "feed.rss"), feed.rss2());
|
||||
return consola.info("Generated rss feed.");
|
||||
}
|
@@ -1,39 +0,0 @@
|
||||
import path from "path";
|
||||
import { writeFileSync } from "fs";
|
||||
import { Feed } from "feed";
|
||||
import { createContentLoader, type SiteConfig } from "vitepress";
|
||||
import { meta } from "./constants";
|
||||
|
||||
export async function genFeed(config: SiteConfig) {
|
||||
const feed = new Feed({
|
||||
title: "FMHY • Monthy Posts",
|
||||
description: meta.description,
|
||||
id: meta.hostname,
|
||||
link: meta.hostname,
|
||||
language: "en",
|
||||
image: "https://github.com/fmhy.png",
|
||||
copyright: "",
|
||||
});
|
||||
|
||||
const posts = await createContentLoader("posts/**/*.md", {
|
||||
excerpt: true,
|
||||
render: true,
|
||||
}).load();
|
||||
|
||||
posts.sort(
|
||||
(a, b) => +new Date(b.frontmatter.date as string) - +new Date(a.frontmatter.date as string),
|
||||
);
|
||||
|
||||
for (const { url, excerpt, frontmatter, html } of posts) {
|
||||
feed.addItem({
|
||||
title: frontmatter.title,
|
||||
id: `${meta.hostname}${url}`,
|
||||
link: `${meta.hostname}${url.split("/posts")[1]}`,
|
||||
description: excerpt,
|
||||
content: html,
|
||||
date: frontmatter.date,
|
||||
});
|
||||
}
|
||||
|
||||
writeFileSync(path.join(config.outDir, "feed.rss"), feed.rss2());
|
||||
}
|
@@ -16,6 +16,12 @@ const formatDate = (raw: string): string => {
|
||||
<section>
|
||||
<h1 class="flex items-center gap-2">Posts</h1>
|
||||
<p>Everything from Monthly Updates to fmhy updates.</p>
|
||||
|
||||
We also have a
|
||||
<a href="/feed.rss" title="RSS feed" class="VPBadge tip">
|
||||
<div class="i-carbon-rss" />
|
||||
RSS feed </a
|
||||
>.
|
||||
</section>
|
||||
<template v-for="year in Object.keys(posts).reverse()" :key="year">
|
||||
<h2>{{ year }}</h2>
|
||||
@@ -35,3 +41,24 @@ const formatDate = (raw: string): string => {
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.VPBadge {
|
||||
border: 1px solid transparent;
|
||||
border-radius: 8px;
|
||||
display: inline-flex;
|
||||
margin-left: 2px;
|
||||
padding: 0 10px;
|
||||
line-height: 22px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
transform: translateY(-2px);
|
||||
align-items: center;
|
||||
gap: 0.2rem;
|
||||
padding-right: 10px;
|
||||
vertical-align: middle;
|
||||
color: var(--vp-badge-tip-text);
|
||||
background-color: var(--vp-custom-block-info-bg);
|
||||
border-color: var(--vp-custom-block-tip-outline);
|
||||
}
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user