Skip to content

Commit 4de3f1f

Browse files
committed
docs: 迁移到 Astro Starlight 生成文档
all: 修正类型
1 parent 26561e7 commit 4de3f1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2410
-1590
lines changed

.github/workflows/deploy-docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ jobs:
3838
uses: peaceiris/actions-gh-pages@v3
3939
with:
4040
github_token: ${{ secrets.GITHUB_TOKEN }}
41-
publish_dir: packages/docs/out
41+
publish_dir: packages/docs/dist

packages/core/src/lyric-player/dom/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { LyricLine } from "../../interfaces.ts";
88
import "../../styles/index.css";
99
import styles from "../../styles/lyric-player.module.css";
1010
import { debounce } from "../../utils/debounce.js";
11-
import { LyricPlayerBase } from "../base.ts";
11+
import { type LyricLineBase, LyricPlayerBase } from "../base.ts";
1212
import { LyricLineEl, type RawLyricLineMouseEvent } from "./lyric-line.ts";
1313

1414
/**
@@ -23,7 +23,7 @@ export class LyricLineMouseEvent extends MouseEvent {
2323
/**
2424
* 歌词行元素
2525
*/
26-
public readonly line: LyricLineEl,
26+
public readonly line: LyricLineBase,
2727
event: MouseEvent,
2828
) {
2929
super(`line-${event.type}`, event);

packages/core/src/lyric-player/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export * from "./canvas/index.ts";
55
export * from "./dom-slim/index.ts";
66
export * from "./dom/index.ts";
77

8-
/**
9-
* 默认导出的歌词播放组件
10-
*/
11-
export const LyricPlayer = DomLyricPlayer;
8+
export {
9+
/**
10+
* 默认导出的歌词播放组件
11+
*/
12+
DomLyricPlayer as LyricPlayer,
13+
};

packages/core/src/test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
* @author SteveXMH
66
*/
77

8+
import * as lyrics from "@applemusic-like-lyrics/lyric";
89
import {
910
type LyricLine as RawLyricLine,
1011
parseLrc,
1112
parseLys,
1213
parseQrc,
14+
parseTTML,
1315
parseYrc,
1416
} from "@applemusic-like-lyrics/lyric";
15-
import { parseTTML } from "@applemusic-like-lyrics/ttml";
1617
import GUI from "lil-gui";
1718
import Stats from "stats.js";
1819
import type { LyricLine } from ".";
@@ -28,6 +29,8 @@ import {
2829
} from "./lyric-player";
2930
import type { SpringParams } from "./utils/spring";
3031

32+
(window as any).lyrics = lyrics;
33+
3134
const audio = document.createElement("audio");
3235
audio.volume = 0.5;
3336
audio.preload = "auto";
@@ -126,7 +129,7 @@ gui
126129
.name("歌词文件")
127130
.onFinishChange(async (url: string) => {
128131
lyricPlayer.setLyricLines(
129-
parseTTML(await (await fetch(url)).text()).lyricLines,
132+
parseTTML(await (await fetch(url)).text()).lines.map(mapTTMLLyric),
130133
);
131134
});
132135
gui
@@ -274,16 +277,16 @@ declare global {
274277
}
275278
}
276279

277-
window.globalLyricPlayer = lyricPlayer;
280+
(window as any).globalLyricPlayer = lyricPlayer;
278281

279-
const waitFrame = (): Promise<void> =>
282+
const waitFrame = (): Promise<number> =>
280283
new Promise((resolve) => requestAnimationFrame(resolve));
281284
const mapLyric = (
282285
line: RawLyricLine,
283286
_i: number,
284287
_lines: RawLyricLine[],
285288
): LyricLine => ({
286-
words: line.words,
289+
words: line.words.map((word) => ({ obscene: false, ...word })),
287290
startTime: line.words[0]?.startTime ?? 0,
288291
endTime:
289292
line.words[line.words.length - 1]?.endTime ?? Number.POSITIVE_INFINITY,
@@ -293,11 +296,16 @@ const mapLyric = (
293296
isDuet: false,
294297
});
295298

299+
const mapTTMLLyric = (line: RawLyricLine): LyricLine => ({
300+
...line,
301+
words: line.words.map((word) => ({ obscene: false, ...word })),
302+
});
303+
296304
async function loadLyric() {
297305
const lyricFile = debugValues.lyric;
298306
const content = await (await fetch(lyricFile)).text();
299307
if (lyricFile.endsWith(".ttml")) {
300-
lyricPlayer.setLyricLines(parseTTML(content).lyricLines);
308+
lyricPlayer.setLyricLines(parseTTML(content).lines.map(mapTTMLLyric));
301309
} else if (lyricFile.endsWith(".lrc")) {
302310
lyricPlayer.setLyricLines(parseLrc(content).map(mapLyric));
303311
} else if (lyricFile.endsWith(".yrc")) {

packages/docs/.gitignore

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
1+
# build output
2+
dist/
3+
# generated types
4+
.astro/
25

36
# dependencies
4-
/node_modules
5-
/.pnp
6-
.pnp.js
7-
.yarn/install-state.gz
7+
node_modules/
88

9-
# testing
10-
/coverage
11-
12-
# next.js
13-
/.next/
14-
/out/
15-
16-
# production
17-
/build
18-
19-
# misc
20-
.DS_Store
21-
*.pem
22-
23-
# debug
9+
# logs
2410
npm-debug.log*
2511
yarn-debug.log*
2612
yarn-error.log*
13+
pnpm-debug.log*
2714

28-
# local env files
29-
.env*.local
3015

31-
# vercel
32-
.vercel
16+
# environment variables
17+
.env
18+
.env.production
3319

34-
# typescript
35-
*.tsbuildinfo
36-
next-env.d.ts
20+
# macOS-specific files
21+
.DS_Store
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"recommendations": ["astro-build.astro-vscode"],
3+
"unwantedRecommendations": []
4+
}

packages/docs/.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"command": "./node_modules/.bin/astro dev",
6+
"name": "Development server",
7+
"request": "launch",
8+
"type": "node-terminal"
9+
}
10+
]
11+
}

packages/docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AMLL Docs
22

3-
AMLL 框架的开发文档页面,使用 Next.js + MDX 编写并部署到 Github Pages。
3+
AMLL 框架的开发文档页面,使用 Astro + React + MDX 编写并部署到 Github Pages。
44

55
[查看文档](https://steve-xmh.github.io/applemusic-like-lyrics/zh-CN)

packages/docs/astro.config.mjs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// @ts-check
2+
import starlight from "@astrojs/starlight";
3+
import { defineConfig } from "astro/config";
4+
import { createStarlightTypeDocPlugin } from "starlight-typedoc";
5+
6+
const [coreStarlightTypeDoc, coreTypeDocSidebarGroup] =
7+
createStarlightTypeDocPlugin();
8+
const [reactStarlightTypeDoc, reactTypeDocSidebarGroup] =
9+
createStarlightTypeDocPlugin();
10+
const [vueStarlightTypeDoc, vueTypeDocSidebarGroup] =
11+
createStarlightTypeDocPlugin();
12+
const [reactFullStarlightTypeDoc, reactFullTypeDocSidebarGroup] =
13+
createStarlightTypeDocPlugin();
14+
const [lyricStarlightTypeDoc, lyricTypeDocSidebarGroup] =
15+
createStarlightTypeDocPlugin();
16+
17+
// https://astro.build/config
18+
export default defineConfig({
19+
base: "applemusic-like-lyrics",
20+
integrations: [
21+
starlight({
22+
favicon: "favicon.ico",
23+
title: "Apple Music-like Lyrics",
24+
customCss: ["./src/styles/custom.css"],
25+
locales: {
26+
root: {
27+
label: "简体中文",
28+
lang: "zh-CN",
29+
},
30+
en: {
31+
label: "English",
32+
lang: "en",
33+
},
34+
},
35+
social: {
36+
github: "https://github.com/Steve-xmh/applemusic-like-lyrics",
37+
},
38+
plugins: [
39+
coreStarlightTypeDoc({
40+
entryPoints: ["../core/src/index.ts"],
41+
output: "reference/core",
42+
tsconfig: "../core/tsconfig.json",
43+
sidebar: {
44+
label: "core",
45+
collapsed: true,
46+
},
47+
typeDoc: {
48+
exclude: ["test.ts"],
49+
},
50+
}),
51+
reactStarlightTypeDoc({
52+
entryPoints: ["../react/src/index.ts"],
53+
output: "reference/react",
54+
tsconfig: "../react/tsconfig.json",
55+
sidebar: {
56+
label: "react",
57+
collapsed: true,
58+
},
59+
}),
60+
vueStarlightTypeDoc({
61+
entryPoints: ["../vue/src/index.ts"],
62+
output: "reference/vue",
63+
tsconfig: "../vue/tsconfig.json",
64+
sidebar: {
65+
label: "vue",
66+
collapsed: true,
67+
},
68+
}),
69+
reactFullStarlightTypeDoc({
70+
entryPoints: ["../react-full/src/index.ts"],
71+
output: "reference/react-full",
72+
tsconfig: "../react-full/tsconfig.json",
73+
sidebar: {
74+
label: "react-full",
75+
collapsed: true,
76+
},
77+
}),
78+
lyricStarlightTypeDoc({
79+
entryPoints: ["../lyric/src/types.d.ts"],
80+
output: "reference/lyric",
81+
tsconfig: "../lyric/tsconfig.json",
82+
sidebar: {
83+
label: "lyric",
84+
collapsed: true,
85+
},
86+
}),
87+
],
88+
sidebar: [
89+
{
90+
label: "核心组件",
91+
items: [{ slug: "guides/core/introduction" }],
92+
},
93+
{
94+
label: "React 绑定",
95+
items: [
96+
{ slug: "guides/react/introduction" },
97+
{ slug: "guides/react/quick-start" },
98+
{ slug: "guides/react/lyric-player" },
99+
{ slug: "guides/react/bg-render" },
100+
],
101+
},
102+
{
103+
label: "AMLL TTML Tools",
104+
items: [
105+
{ slug: "guides/ttml-tools/introduction" },
106+
{ slug: "guides/ttml-tools/tips" },
107+
],
108+
},
109+
{
110+
label: "接口参考",
111+
items: [
112+
coreTypeDocSidebarGroup,
113+
reactTypeDocSidebarGroup,
114+
vueTypeDocSidebarGroup,
115+
reactFullTypeDocSidebarGroup,
116+
lyricTypeDocSidebarGroup,
117+
],
118+
},
119+
],
120+
}),
121+
],
122+
});

packages/docs/next.config.mjs

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)