解析抖音视频
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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: '视频',
|
||||||
|
|||||||
Reference in New Issue
Block a user