mirror of
https://github.com/rustdesk/doc.rustdesk.com.git
synced 2026-04-07 16:26:25 +00:00
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
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';
|
|
}
|
|
});
|
|
};
|
|
};
|