From 23ce20af6c2e064ff4c62651506a643cdbce0dc5 Mon Sep 17 00:00:00 2001 From: "@andatoshiki" Date: Sat, 16 Sep 2023 19:58:42 -0700 Subject: [PATCH] chore(rm): remove deprecated redundant code features from prior version that are not in used for cleaner project directory structure --- docs/.vitepress/theme/rss.ts | 77 --------------------------- docs/.vitepress/theme/utils.ts | 45 ---------------- docs/.vitepress/utils/genFeed.js | 44 --------------- docs/.vitepress/utils/posts.data.d.ts | 10 ---- docs/.vitepress/utils/posts.data.js | 65 ---------------------- scripts/verifyCommit.js | 17 ------ 6 files changed, 258 deletions(-) delete mode 100644 docs/.vitepress/theme/rss.ts delete mode 100644 docs/.vitepress/theme/utils.ts delete mode 100644 docs/.vitepress/utils/genFeed.js delete mode 100644 docs/.vitepress/utils/posts.data.d.ts delete mode 100644 docs/.vitepress/utils/posts.data.js delete mode 100644 scripts/verifyCommit.js diff --git a/docs/.vitepress/theme/rss.ts b/docs/.vitepress/theme/rss.ts deleted file mode 100644 index fa8595ea..00000000 --- a/docs/.vitepress/theme/rss.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { dirname } from 'path' -import fg from 'fast-glob' -import fs from 'fs-extra' -import matter from 'gray-matter' -import MarkdownIt from 'markdown-it' -import type { FeedOptions, Item } from 'feed' -import { Feed } from 'feed' - -const DOMAIN = 'https://note.toshiki.dev' -const AUTHOR = { - name: 'Anda Toshiki', - email: 'hello@toshiki.dev', - link: DOMAIN, -} -const OPTIONS: FeedOptions = { - title: "Toshiki's Notebook", - description: "Toshiki's web notebook built upon Vitepress and deployed via Vercel!", - id: `${DOMAIN}/`, - link: `${DOMAIN}/`, - copyright: 'MIT License', - feedLinks: { - json: DOMAIN + '/feed.json', - atom: DOMAIN + '/feed.atom', - rss: DOMAIN + '/feed.xml', - }, - author: AUTHOR, - image: 'https://note.toshiki.dev/logos/logo-308px.svg', - favicon: 'https://note.toshiki.dev/logos/logo-308px.svg', -} - -const markdown = MarkdownIt({ - html: true, - breaks: true, - linkify: true, -}) - -export async function buildDocsRSS() { - const posts = await generateRSS() - writeFeed('feed', posts) -} - -async function generateRSS() { - const files = await fg('docs/*.md') - - const posts: any[] = ( - await Promise.all( - files - .filter(i => !i.includes('index')) - .map(async i => { - const raw = await fs.readFile(i, 'utf-8') - const { data, content } = matter(raw) - const html = markdown.render(content).replace('src="/', `src="${DOMAIN}/`) - - return { - ...data, - date: new Date(data.date), - content: html, - author: [AUTHOR], - link: `${DOMAIN}/${i.replace('.md', '.html')}`, - } - }) - ) - ).filter(Boolean) - - posts.sort((a, b) => +new Date(b.date) - +new Date(a.date)) - return posts -} - -async function writeFeed(name: string, items: Item[]) { - const feed = new Feed(OPTIONS) - items.forEach(item => feed.addItem(item)) - - await fs.ensureDir(dirname(`./dist/${name}`)) - await fs.writeFile(`./dist/${name}.xml`, feed.rss2(), 'utf-8') - await fs.writeFile(`./dist/${name}.atom`, feed.atom1(), 'utf-8') - await fs.writeFile(`./dist/${name}.json`, feed.json1(), 'utf-8') -} diff --git a/docs/.vitepress/theme/utils.ts b/docs/.vitepress/theme/utils.ts deleted file mode 100644 index f5db9918..00000000 --- a/docs/.vitepress/theme/utils.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 格式化时间 - * - * @param date 待格式化时间 - * @returns 格式化后的时间(YYYY/MM/dd AM hh:mm) - */ -export function formatDate(date) { - const formatDate = new Date(date) - return formatDate.toLocaleString('en', { - year: 'numeric', - month: 'numeric', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - }) -} - -/** - * 获取 URL 路径中的指定参数 - * - * @param paramName 参数名 - * @returns 参数值 - */ -export function getQueryParam(paramName) { - const reg = new RegExp('(^|&)' + paramName + '=([^&]*)(&|$)') - let value = decodeURIComponent(window.location.search.substr(1)).match(reg) - if (value != null) { - return unescape(value[2]) - } - return null -} - -/** - * 跳转到指定链接 - * - * @param paramName 参数名 - * @param paramValue 参数值 - */ -export function goToLink(url, paramName, paramValue) { - if (paramName) { - window.location.href = url + '?' + paramName + '=' + paramValue - } else { - window.location.href = url - } -} diff --git a/docs/.vitepress/utils/genFeed.js b/docs/.vitepress/utils/genFeed.js deleted file mode 100644 index 46ea9ecf..00000000 --- a/docs/.vitepress/utils/genFeed.js +++ /dev/null @@ -1,44 +0,0 @@ -const fs = require('fs') -const path = require('path') -const { Feed } = require('feed') -const { load } = require('./posts.data') -const url = `https://note.toshiki.dev/` - -genFeed() - -async function genFeed() { - const posts = await load(true) - const cwd = process.cwd() - const feed = new Feed({ - title: "Toshiki's Notebook", - description: "Toshiki's web notebook served via Vitepress!", - id: url, - link: url, - language: 'en-US', - image: `${url}/logos/logo-308px.png`, - favicon: `${url}/favicon.ico`, - copyright: 'Copyright © 2023-2023 Anda Toshiki, LoliLab and Toshiki Dev present' - }) - - posts.forEach(post => { - const file = path.resolve(cwd, `dist/${post.href}`) - const rendered = fs.readFileSync(file, 'utf-8') - const content = rendered.match(/([\s\S]*)<\/body>/) - - feed.addItem({ - title: post.title, - id: `${url}${post.href}`, - link: `${url}${post.href}`, - description: post.excerpt, - content: content[1], - author: [ - { - name: post.data.author, - link: post.data.twitter ? `https://twitter.com/${post.data.twitter}` : undefined - } - ] - }) - }) - - fs.writeFileSync(path.resolve(cwd, 'dist/feed.rss'), feed.rss2()) -} diff --git a/docs/.vitepress/utils/posts.data.d.ts b/docs/.vitepress/utils/posts.data.d.ts deleted file mode 100644 index 26a307cc..00000000 --- a/docs/.vitepress/utils/posts.data.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface PostData { - title: string - href: string - create: number - update: number - keywords?: string[] - cover?: string - excerpt: string -} -export declare const data: PostData[] diff --git a/docs/.vitepress/utils/posts.data.js b/docs/.vitepress/utils/posts.data.js deleted file mode 100644 index e415e8ea..00000000 --- a/docs/.vitepress/utils/posts.data.js +++ /dev/null @@ -1,65 +0,0 @@ -const fs = require('fs') -const path = require('path') -const matter = require('gray-matter') -const { createMarkdownRenderer } = require('vitepress') - -const md = createMarkdownRenderer(process.cwd()) - -module.exports = { - watch: '../../docs/*.md', - load(asFeed = false) { - const postDir = path.resolve(__dirname, '../../docs') - return fs - .readdirSync(postDir) - .map(file => getPost(file, postDir, asFeed)) - .sort((a, b) => b.date.time - a.date.time) - } -} - -const cache = new Map() - -function getPost(file, postDir, asFeed = false) { - const fullePath = path.join(postDir, file) - const timestamp = fs.statSync(fullePath).mtimeMs - - const cached = cache.get(fullePath) - if (cached && timestamp === cached.timestamp) { - return cached.post - } - - const src = fs.readFileSync(fullePath, 'utf-8') - const { data, excerpt } = matter(src, { excerpt: true }) - - const post = { - title: data.title, - href: `${file.replace(/\.md$/, '.html')}`, - date: formatDate(data.date), - excerpt: md.render(excerpt) - } - if (asFeed) { - // only attach these when building the RSS feed to avoid bloating the - // client bundle size - post.data = data - } - - cache.set(fullePath, { - timestamp, - post - }) - return post -} - -function formatDate(date) { - if (!(date instanceof Date)) { - date = new Date(date) - } - date.setUTCHours(12) - return { - time: +date, - string: date.toLocaleDateString('en-US', { - year: 'numeric', - month: 'long', - day: 'numeric' - }) - } -} diff --git a/scripts/verifyCommit.js b/scripts/verifyCommit.js deleted file mode 100644 index a29c2b77..00000000 --- a/scripts/verifyCommit.js +++ /dev/null @@ -1,17 +0,0 @@ -const msg = require('fs') - .readFileSync('.git/COMMIT_EDITMSG', 'utf-8') - .trim() - -const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ -const mergeRe = /^(Merge pull request|Merge branch)/ -if (!commitRE.test(msg)) { - if(!mergeRe.test(msg)){ - console.log('git commit message does not pass validation') - - console.error(`git commit message format error, use \" title(scope): desc\" as the format`) - process.exit(1) - } - -}else{ - console.log('git commit message validation test passes') -} \ No newline at end of file