-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
175 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import path from "path"; | ||
import { promises as fs } from "fs"; | ||
import type { FeedOptions, Item } from "feed"; | ||
import { Feed } from "feed"; | ||
import themeConfig from "../config.theme"; | ||
import { BASE_PATH, withBaseURL, joinURL } from "../config.utils"; | ||
import postLoader from "./posts.loader"; | ||
|
||
const DOMAIN_PRODUCTION = "blog.octobug.site"; | ||
const DOMAIN_STAGING = "octobug.github.io"; | ||
|
||
const DOMAIN = BASE_PATH ? DOMAIN_STAGING : DOMAIN_PRODUCTION; | ||
const BASE_URL = `https://${DOMAIN}${withBaseURL("/")}`; | ||
const AUTHOR = { | ||
name: "Octobug", | ||
email: "[email protected]", | ||
link: BASE_URL, | ||
}; | ||
const OPTIONS: FeedOptions = { | ||
title: "WhaleVocal", | ||
description: "Octobug's Blog", | ||
id: BASE_URL, | ||
link: BASE_URL, | ||
copyright: themeConfig.footer.copyright, | ||
feedLinks: { | ||
atom: joinURL(BASE_URL, "feed.atom"), | ||
rss: joinURL(BASE_URL, "rss.xml"), | ||
}, | ||
author: AUTHOR, | ||
image: joinURL(BASE_URL, "avatar.png"), | ||
favicon: joinURL(BASE_URL, "avatar.png"), | ||
}; | ||
|
||
export async function buildFeed(outDir: string) { | ||
const posts = await generateContents(); | ||
|
||
const feed = new Feed(OPTIONS); | ||
posts.forEach(item => feed.addItem(item)); | ||
|
||
await fs.writeFile(path.join(outDir, "feed.atom"), feed.atom1(), "utf8"); | ||
await fs.writeFile(path.join(outDir, "rss.xml"), feed.rss2(), "utf8"); | ||
} | ||
|
||
async function generateContents(): Promise<Item[]> { | ||
const loader = await postLoader({ | ||
includeSrc: false, | ||
render: true, | ||
excerpt: true, | ||
}); | ||
const allPosts = await loader.load(); | ||
|
||
return await Promise.all( | ||
allPosts.map(async p => { | ||
return { | ||
title: p.frontmatter.title, | ||
id: p.url, | ||
link: joinURL(BASE_URL, p.url), | ||
date: p.frontmatter.date, | ||
description: p.excerpt, | ||
content: p.html, | ||
category: [p.frontmatter.sort].map(s => { return { name: s }; }), | ||
author: [AUTHOR], | ||
} satisfies Item; | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,12 @@ | ||
// https://vitepress.dev/guide/data-loading | ||
import { createContentLoader, ContentData } from "vitepress"; | ||
import readingTime from "reading-time"; | ||
import extendedConfig from "../config.theme"; | ||
import { withBaseURL } from "../config.utils"; | ||
import getLocation from "./locations"; | ||
import { ContentData } from "vitepress"; | ||
import postLoader from "./posts.loader"; | ||
|
||
declare const data: ContentData[]; | ||
export { data }; | ||
|
||
// Title Workaround | ||
function extractTile(text: string) { | ||
const titlePattern = /---\n\n# (?<title>.*)\n/; | ||
const match = text.match(titlePattern); | ||
return match?.groups?.title || "NonTitled"; | ||
} | ||
|
||
export default createContentLoader(extendedConfig.mdfilePatterns, { | ||
export default await postLoader({ | ||
includeSrc: true, | ||
transform(rawData) { | ||
return rawData.map(p => { | ||
const rt = readingTime(p.src || ""); | ||
p.frontmatter.title = extractTile(p.src || ""); | ||
p.frontmatter.datetime = new Date(p.frontmatter.date); | ||
p.frontmatter.location = getLocation(p.frontmatter.spot); | ||
p.frontmatter.readingTime = rt.text; | ||
p.frontmatter.words = rt.words; | ||
p.url = withBaseURL(p.url.replace("/README", "")); | ||
return p; | ||
}).sort((a, b) => { | ||
return b.frontmatter.datetime - a.frontmatter.datetime; | ||
}); | ||
} | ||
render: false, | ||
excerpt: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// https://vitepress.dev/guide/data-loading | ||
import { createContentLoader } from "vitepress"; | ||
import readingTime from "reading-time"; | ||
import extendedConfig from "../config.theme"; | ||
import { withBaseURL } from "../config.utils"; | ||
import getLocation from "./locations"; | ||
|
||
// Title Workaround | ||
function extractTile(text: string) { | ||
const titlePattern = /---\n\n# (?<title>.*)\n/; | ||
const match = text.match(titlePattern); | ||
return match?.groups?.title || "NonTitled"; | ||
} | ||
|
||
export default async (options) => { | ||
const { | ||
includeSrc = true, | ||
render = false, | ||
excerpt = false, | ||
} = options; | ||
|
||
return createContentLoader(extendedConfig.mdfilePatterns, { | ||
includeSrc, | ||
render, | ||
excerpt, | ||
transform(rawData) { | ||
return rawData.map(p => { | ||
const rt = readingTime(p.src || ""); | ||
p.frontmatter.title = extractTile(p.src || ""); | ||
p.frontmatter.datetime = new Date(p.frontmatter.date); | ||
p.frontmatter.location = getLocation(p.frontmatter.spot); | ||
p.frontmatter.readingTime = rt.text; | ||
p.frontmatter.words = rt.words; | ||
p.url = withBaseURL(p.url.replace("/README", "")); | ||
return p; | ||
}).sort((a, b) => { | ||
return b.frontmatter.datetime - a.frontmatter.datetime; | ||
}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters