mirror of
https://github.com/rustdesk/doc.rustdesk.com.git
synced 2026-04-15 04:06:26 +00:00
initialize with https://github.com/onwidget/astrowind
This commit is contained in:
48
v3/src/utils/frontmatter.ts
Normal file
48
v3/src/utils/frontmatter.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import getReadingTime from 'reading-time';
|
||||
import { toString } from 'mdast-util-to-string';
|
||||
import { visit } from 'unist-util-visit';
|
||||
import type { MarkdownAstroData, RehypePlugin, RemarkPlugin } from '@astrojs/markdown-remark';
|
||||
|
||||
export const readingTimeRemarkPlugin: RemarkPlugin = () => {
|
||||
return function (tree, file) {
|
||||
const textOnPage = toString(tree);
|
||||
const readingTime = Math.ceil(getReadingTime(textOnPage).minutes);
|
||||
|
||||
(file.data.astro as MarkdownAstroData).frontmatter.readingTime = readingTime;
|
||||
};
|
||||
};
|
||||
|
||||
export const responsiveTablesRehypePlugin: RehypePlugin = () => {
|
||||
return function (tree) {
|
||||
if (!tree.children) return;
|
||||
|
||||
for (let i = 0; i < tree.children.length; i++) {
|
||||
const child = tree.children[i];
|
||||
|
||||
if (child.type === 'element' && child.tagName === 'table') {
|
||||
tree.children[i] = {
|
||||
type: 'element',
|
||||
tagName: 'div',
|
||||
properties: {
|
||||
style: 'overflow:auto',
|
||||
},
|
||||
children: [child],
|
||||
};
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const lazyImagesRehypePlugin: RehypePlugin = () => {
|
||||
return function (tree) {
|
||||
if (!tree.children) return;
|
||||
|
||||
visit(tree, 'element', function (node) {
|
||||
if (node.tagName === 'img') {
|
||||
node.properties.loading = 'lazy';
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user