refactor: convert JavaScript files to TypeScript

This commit is contained in:
Jumpei Ogawa
2024-08-16 17:24:23 +09:00
parent fcc9e20a1b
commit e60c6c1069
4 changed files with 1 additions and 1 deletions

39
src/utils/frontmatter.ts Normal file
View File

@@ -0,0 +1,39 @@
import getReadingTime from 'reading-time';
import { toString } from 'mdast-util-to-string';
import lazyLoadPlugin from 'rehype-plugin-image-native-lazy-loading';
export function readingTimeRemarkPlugin() {
return function (tree, file) {
const textOnPage = toString(tree);
const readingTime = Math.ceil(getReadingTime(textOnPage).minutes);
file.data.astro.frontmatter.readingTime = readingTime;
};
}
export function responsiveTablesRehypePlugin() {
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') {
const wrapper = {
type: 'element',
tagName: 'div',
properties: {
style: 'overflow:auto',
},
children: [child],
};
tree.children[i] = wrapper;
i++;
}
}
};
}
export const lazyImagesRehypePlugin = lazyLoadPlugin;