mirror of
https://github.com/andatoshiki/toshiki-notebook.git
synced 2026-06-06 00:46:29 +00:00
chore(rm): remove deprecated redundant code features from prior version that are not in used for cleaner project directory structure
This commit is contained in:
parent
740add740e
commit
23ce20af6c
@ -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')
|
|
||||||
}
|
|
||||||
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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(/<body>([\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())
|
|
||||||
}
|
|
||||||
10
docs/.vitepress/utils/posts.data.d.ts
vendored
10
docs/.vitepress/utils/posts.data.d.ts
vendored
@ -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[]
|
|
||||||
@ -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'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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')
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user