解析抖音视频

This commit is contained in:
宇阳
2025-01-11 18:30:26 +08:00
parent 688c572635
commit 8ed9ed6429
2 changed files with 52 additions and 0 deletions

View File

@@ -168,4 +168,11 @@
position: relative; position: relative;
cursor: not-allowed; cursor: not-allowed;
} }
.douyin {
min-width: 320px;
min-height: 720px;
border-radius: 10px;
margin: 10px 0;
}
} }

View File

@@ -19,9 +19,54 @@ import 'katex/dist/katex.css';
import rehypeCallouts from 'rehype-callouts'; import rehypeCallouts from 'rehype-callouts';
import 'rehype-callouts/theme/obsidian'; import 'rehype-callouts/theme/obsidian';
import { remarkMark } from 'remark-mark-highlight'; import { remarkMark } from 'remark-mark-highlight';
import type { Plugin } from 'unified';
import { visit } from 'unist-util-visit';
import type { Element, Root } from 'hast';
const rehypeDouyinVideo: Plugin<[], Root> = () => {
return (tree) => {
visit(tree, 'element', (node: Element) => {
if (node.tagName === 'p') {
const link = node.children[0];
if (
link.type === 'element' &&
link.tagName === 'a' &&
link.properties?.href &&
typeof link.properties.href === 'string'
) {
const match = /(?:ixigua\.com|douyin\.com)\/(\d+)/.exec(link.properties.href);
if (match) {
const videoId = match[1];
const wrapperDiv = {
type: 'element',
tagName: 'div',
properties: {
className: 'flex justify-center'
},
children: [{
type: 'element',
tagName: 'iframe',
properties: {
src: `https://open.douyin.com/player/video?vid=${videoId}&autoplay=0`,
referrerPolicy: 'unsafe-url',
allowFullScreen: true,
className: 'douyin'
},
children: []
}]
};
Object.assign(node, wrapperDiv);
}
}
}
});
};
};
const videos = (): BytemdPlugin => { const videos = (): BytemdPlugin => {
return { return {
rehype: (processor) => processor.use(rehypeDouyinVideo),
actions: [ actions: [
{ {
title: '视频', title: '视频',