Skip to content

Commit 60d39e5

Browse files
chore: add YouTube video
1 parent 8c75e91 commit 60d39e5

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

.vitepress/config.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'vitepress';
2+
import markdownItYouTubeEmbed from './markdown-it-youtube-embed.js';
23

34
// https://vitepress.dev/reference/site-config
45
export default defineConfig({
@@ -106,4 +107,9 @@ export default defineConfig({
106107
},
107108
],
108109
},
110+
markdown: {
111+
config: (md) => {
112+
md.use(markdownItYouTubeEmbed);
113+
},
114+
},
109115
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { PluginWithOptions } from 'markdown-it';
2+
import { RuleCore } from 'markdown-it/lib/parser_core.mjs';
3+
4+
const markdownItYouTubeEmbed: PluginWithOptions<void> = (md) => {
5+
const youtubeEmbedRule: RuleCore = (state) => {
6+
const tokens = state.tokens;
7+
8+
for (let i = 0; i < tokens.length; i++) {
9+
const token = tokens[i];
10+
11+
if (
12+
token.type === 'inline' &&
13+
token.children &&
14+
token.children.length >= 1 &&
15+
token.children[0].type === 'link_open'
16+
) {
17+
const linkToken = token.children[0];
18+
const href = linkToken.attrGet('href');
19+
20+
if (href && href.startsWith('https://www.youtube.com/watch?v=')) {
21+
const videoId = href.split('v=')[1];
22+
const iframeHtml = `
23+
<div class="responsive-video">
24+
<iframe
25+
src="https://www.youtube.com/embed/${videoId}"
26+
frameborder="0"
27+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
28+
allowfullscreen>
29+
</iframe>
30+
</div>
31+
`;
32+
33+
// Replace current token with a new HTML block token
34+
const newToken = new state.Token('html_block', '', 0);
35+
newToken.content = iframeHtml;
36+
tokens[i] = newToken;
37+
}
38+
}
39+
}
40+
};
41+
42+
md.core.ruler.push('youtube_embed', youtubeEmbedRule);
43+
};
44+
45+
export default markdownItYouTubeEmbed;

.vitepress/theme/custom.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,20 @@
2525
.VPSidebar {
2626
padding-bottom: 20px !important;
2727
}
28+
29+
.responsive-video {
30+
position: relative;
31+
padding-bottom: 56.25%; /* 16:9 aspect ratio */
32+
height: 0;
33+
overflow: hidden;
34+
max-width: 100%;
35+
background: #000;
36+
}
37+
38+
.responsive-video iframe {
39+
position: absolute;
40+
top: 0;
41+
left: 0;
42+
width: 100%;
43+
height: 100%;
44+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ It supports the following frameworks:
1313
- Any other framework or setup by implementing a simple function in TypeScript
1414
- ... (Need support for another framework? Let me know!)
1515

16+
[![Video presentation of Lambda Live Debugger](https://img.youtube.com/vi/BrhybwyDM0I/0.jpg)](https://www.youtube.com/watch?v=BrhybwyDM0I)
17+
1618
## Why?
1719

1820
Serverless is amazing and solves many issues with traditional systems. However, writing code for Lambda functions can be challenging. The cycle of writing, deploying, running, fixing, and redeploying is time-consuming and tedious. You could use tools to run Lambda locally or use unit/integration tests; those approaches often don't replicate the actual environment closely enough.

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"compilerOptions": {
44
"allowJs": true,
55
"checkJs": true,
6-
"outDir": "./dist",
7-
"rootDir": "./src"
6+
"outDir": "./dist"
87
},
98
"include": ["src/**/*", "test/**/*", "*.*", ".vitepress/**/*"],
109
"exclude": ["node_modules", "dist"]

0 commit comments

Comments
 (0)