feat: add separate stylesheet for prismjs code block theme

This commit is contained in:
Timothy Lin
2021-09-07 00:05:56 +08:00
parent 489a8c9c55
commit a30b452920
5 changed files with 129 additions and 57 deletions

View File

@ -20,20 +20,6 @@ import rehypePrismPlus from 'rehype-prism-plus'
const root = process.cwd()
const tokenClassNames = {
tag: 'text-code-red',
'attr-name': 'text-code-yellow',
'attr-value': 'text-code-green',
deleted: 'text-code-red',
inserted: 'text-code-green',
punctuation: 'text-code-white',
keyword: 'text-code-purple',
string: 'text-code-green',
function: 'text-code-blue',
boolean: 'text-code-red',
comment: 'text-gray-400 italic',
}
export function getFiles(type) {
const prefixPaths = path.join(root, 'data', type)
const files = getAllFilesRecursively(prefixPaths)
@ -100,16 +86,6 @@ export async function getFileBySlug(type, slug) {
rehypeAutolinkHeadings,
rehypeKatex,
[rehypePrismPlus, { ignoreMissing: true }],
() => {
return (tree) => {
visit(tree, 'element', (node, index, parent) => {
let [token, type] = node.properties.className || []
if (token === 'token') {
node.properties.className = [tokenClassNames[type]]
}
})
}
},
]
return options
},