Browse Source

支持嵌入视频

pull/16/head
hole-thu 3 years ago
parent
commit
f91c2c8e0c
  1. 2
      public/index.html
  2. 2
      src/Common.css
  3. 32
      src/Common.js

2
public/index.html

@ -6,6 +6,8 @@
<link rel="icon" href="%PUBLIC_URL%/static/favicon/512.png"> <link rel="icon" href="%PUBLIC_URL%/static/favicon/512.png">
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<meta name="referrer" content="no-referrer">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<link rel="shortcut icon" href="%PUBLIC_URL%/static/favicon/512.png"> <link rel="shortcut icon" href="%PUBLIC_URL%/static/favicon/512.png">
<link rel="manifest" href="./static/manifest.json"> <link rel="manifest" href="./static/manifest.json">

2
src/Common.css

@ -59,7 +59,7 @@
margin-left: .15rem; margin-left: .15rem;
} }
.ext-img { .ext-img, .ext-video {
max-width: 100%; max-width: 100%;
max-height: 2000px; max-height: 2000px;
display: block; display: block;

32
src/Common.js

@ -24,6 +24,15 @@ function escape_regex(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
} }
function is_video(s) {
try {
let url = new URL(s);
return url.pathname.endsWith('.mp4') || url.pathname.endsWith('.mov');
} catch (e) {
return false;
}
}
export function build_highlight_re( export function build_highlight_re(
txt, txt,
split = ' ', split = ' ',
@ -150,15 +159,20 @@ export class HighlightedMarkdown extends Component {
/## /##
</span> </span>
) : rule === 'url' ? ( ) : rule === 'url' ? (
<a <>
href={normalize_url(p)} <a
className="ext-link" href={normalize_url(p)}
target="_blank" className="ext-link"
rel="noopener noreferrer" target="_blank"
> rel="noopener noreferrer"
{p} >
<span className="icon icon-new-tab" /> {p}
</a> <span className="icon icon-new-tab" />
</a>
{is_video(p) && (
<video className="ext-video" src={p} controls loop/>
)}
</>
) : rule === 'pid' ? ( ) : rule === 'pid' ? (
<a <a
href={'#' + p} href={'#' + p}

Loading…
Cancel
Save