Skip to content

Commit dc3447f

Browse files
committed
Add documentation workflow
Signed-off-by: Brian Wo <[email protected]>
1 parent 5cc7455 commit dc3447f

File tree

5 files changed

+97
-17
lines changed

5 files changed

+97
-17
lines changed

.github/workflows/doc.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Generate documentation for GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
14+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
15+
concurrency:
16+
group: "pages"
17+
cancel-in-progress: false
18+
19+
jobs:
20+
doc:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: actions/configure-pages@v5
25+
- uses: dart-lang/setup-dart@v1
26+
- run: dart doc
27+
- name: Upload artifact
28+
uses: actions/upload-pages-artifact@v3
29+
with:
30+
path: "./doc/api"
31+
deploy:
32+
environment:
33+
name: github-pages
34+
url: ${{ steps.deployments.outputs.page_url }}
35+
runs-on: ubuntu-latest
36+
needs: build
37+
steps:
38+
- name: Deploy to GitHub Pages
39+
id: deployment
40+
uses: actions/deploy-pages@v4

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# https://dart.dev/guides/libraries/private-files
22
# Created by `dart pub`
33
.dart_tool/
4+
5+
# Generated doc from `dart doc`
6+
doc/

lib/kara.dart

+49-12
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ KaraTime? _parseTimestamp(String line) {
8888
} else {
8989
return null;
9090
}
91-
String original = lyricSplit.elementAt(1);
9291

93-
String? roman;
94-
String? furigana;
92+
String original = lyricSplit.elementAt(1);
93+
String? roman = lyricSplit.elementAtOrNull(2);
94+
String? furigana = lyricSplit.elementAtOrNull(3);
9595

9696
return KaraTime(
9797
start: start,
@@ -112,10 +112,13 @@ Kara? parse(String raw) {
112112
late int year;
113113
late String album;
114114
late List<String> languages;
115+
Map<int, String> singers = {};
115116

116117
KaraSection currentSection = KaraSection.header;
117-
KaraLine? currentLine;
118-
Map<int, String> singers = {};
118+
List<bool>? currentSingers;
119+
String? currentLyric;
120+
Duration? currentStart;
121+
Duration? currentEnd;
119122

120123
List<KaraLine> lines = [];
121124
List<KaraTime> time = [];
@@ -140,13 +143,7 @@ Kara? parse(String raw) {
140143
_ => KaraSection.header,
141144
};
142145

143-
if (currentSection.isSongStructure && currentLine != null) {
144-
lines = [
145-
...lines,
146-
currentLine,
147-
];
148-
currentLine = null;
149-
}
146+
if (currentSection.isSongStructure && time.isNotEmpty) {}
150147
}
151148

152149
if (currentSection == KaraSection.header) {
@@ -186,9 +183,49 @@ Kara? parse(String raw) {
186183

187184
if (currentSection.isSongStructure) {
188185
if (_parseTimestamp(line) case KaraTime parsedTimestamp) {
186+
if (currentStart == null ||
187+
currentEnd == null ||
188+
parsedTimestamp.start < currentStart) {
189+
currentStart = parsedTimestamp.start;
190+
currentEnd = parsedTimestamp.end;
191+
continue;
192+
}
193+
189194
time.add(parsedTimestamp);
190195
continue;
191196
}
197+
198+
if (time.isNotEmpty) {
199+
if (currentLyric == null ||
200+
currentStart == null ||
201+
currentEnd == null) {
202+
continue;
203+
}
204+
lines.add(KaraLine(
205+
section: currentSection,
206+
singers: currentSingers,
207+
lyric: currentLyric,
208+
start: currentStart,
209+
end: currentEnd,
210+
time: time,
211+
));
212+
time = [];
213+
}
214+
215+
final parsed = _parseKeyValue(line);
216+
if (parsed != null) {
217+
final tempSingers = List<bool>.generate(
218+
singers.length,
219+
(index) => false,
220+
growable: false,
221+
);
222+
parsed.value
223+
.split(",")
224+
.map((e) => int.tryParse(e.trim()))
225+
.forEach((element) {
226+
// TODO: convert number to [true,true,false]
227+
});
228+
}
192229
}
193230
}
194231

lib/src/line.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ typedef KaraTranslation = Map<String, String>;
1111
class KaraLine {
1212
const KaraLine({
1313
required this.section,
14-
required this.singers,
14+
this.singers,
1515
required this.lyric,
1616
required this.start,
1717
required this.end,
@@ -20,7 +20,7 @@ class KaraLine {
2020
});
2121

2222
final KaraSection section;
23-
final List<bool> singers;
23+
final List<bool>? singers;
2424
final String lyric;
2525
final KaraTranslation? translations;
2626
final Duration start;

lib/src/section.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be found
33
// in LICENSE or at https://opensource.org/license/BSD-3-clause.
44

5-
/// Mark a section of Kara file
5+
/// Mark a section of Kara file.
66
enum KaraSection {
77
/// Contains metadata of the song.
88
header,
@@ -45,13 +45,13 @@ enum KaraSection {
4545

4646
/// Use to distinguish song sections.
4747
///
48-
/// Also check [intro], [verse], [preChorus], [chorus], [posChrous], and
48+
/// Also check [intro], [verse], [preChorus], [chorus], [postChrous], and
4949
/// [postBridge].
5050
bridge,
5151

5252
/// Use to distinguish song sections.
5353
///
54-
/// Also check [intro], [verse], [preChorus], [chorus], [posChrous], and
54+
/// Also check [intro], [verse], [preChorus], [chorus], [postChrous], and
5555
/// [bridge].
5656
postBridge;
5757

0 commit comments

Comments
 (0)