Skip to content

Commit

Permalink
add nextjs tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwu51 committed Jun 15, 2024
1 parent e5ba48f commit ccf3191
Show file tree
Hide file tree
Showing 7 changed files with 886 additions and 1 deletion.
807 changes: 807 additions & 0 deletions 24.06/nextjs14教程.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/blog/[month]/[slug]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import querystring from 'querystring';
import Discussion from '@/app/components/Discussion';
import { Button, Card, Tooltip, DirectoryTree } from '@/app/components/Antd';
import { Tabs, Item } from '@/app/components/Tabs';
import AsciinemaPlayer from '@/app/components/AsciinemaPlayer';

export default async function Post({ params }) {
let { month, slug } = params;
Expand Down Expand Up @@ -91,7 +92,8 @@ export default async function Post({ params }) {
Tooltip,
DirectoryTree,
Tabs,
Item
Item,
AsciinemaPlayer
}} />
</main>
<div className='container mx-auto max-w-[1200px] py-12 px-0'>
Expand Down
21 changes: 21 additions & 0 deletions app/components/AsciinemaPlayer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use client'
import React, { useEffect, useRef } from 'react';
import 'asciinema-player/dist/bundle/asciinema-player.css';

const AsciinemaPlayer = ({ src, options }) => {
const playerRef = useRef(null);
const hasInitialized = useRef(false);
useEffect(() => {
// 动态导入 asciinema-player 以确保它只在客户端加载
import('asciinema-player').then((asciinemaPlayer) => {
if (playerRef.current && !hasInitialized.current) {
asciinemaPlayer.create(src, playerRef.current, options);
hasInitialized.current = true;
}
});
}, []);

return <div ref={playerRef} ></div>;
};

export default AsciinemaPlayer;
10 changes: 10 additions & 0 deletions app/demo/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import AsciinemaPlayer from '@/app/components/AsciinemaPlayer'
export default function() {
return <>
<AsciinemaPlayer src="https://asciinema.org/a/569727.cast" options = {{
speed: 2,
theme: 'tango',
autoplay: true,
}}/>
</>
}
5 changes: 5 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,9 @@ nav>ol.toc-level-1 {
.toc-wrapper .toc a {
font-weight: 700;
color: var(--w-indigo-light);
}

.markdown-body .ap-player pre {
margin: 0;
padding: 0;
}
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@react-types/shared": "^3.23.1",
"@types/mdx": "^2.0.13",
"antd": "^5.18.0",
"asciinema-player": "^3.7.1",
"clsx": "^2.1.1",
"esbuild": "^0.21.4",
"esbuild-plugin-css-modules": "^0.3.0",
Expand Down

0 comments on commit ccf3191

Please sign in to comment.