Skip to content

Commit

Permalink
Add documentation workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Wo <[email protected]>
  • Loading branch information
brainwo committed Aug 10, 2024
1 parent 5cc7455 commit dc3447f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 17 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Generate documentation for GitHub Pages

on:
push:
branches:
- main

permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/configure-pages@v5
- uses: dart-lang/setup-dart@v1
- run: dart doc
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: "./doc/api"
deploy:
environment:
name: github-pages
url: ${{ steps.deployments.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Generated doc from `dart doc`
doc/
61 changes: 49 additions & 12 deletions lib/kara.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ KaraTime? _parseTimestamp(String line) {
} else {
return null;
}
String original = lyricSplit.elementAt(1);

String? roman;
String? furigana;
String original = lyricSplit.elementAt(1);
String? roman = lyricSplit.elementAtOrNull(2);
String? furigana = lyricSplit.elementAtOrNull(3);

return KaraTime(
start: start,
Expand All @@ -112,10 +112,13 @@ Kara? parse(String raw) {
late int year;
late String album;
late List<String> languages;
Map<int, String> singers = {};

KaraSection currentSection = KaraSection.header;
KaraLine? currentLine;
Map<int, String> singers = {};
List<bool>? currentSingers;
String? currentLyric;
Duration? currentStart;
Duration? currentEnd;

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

if (currentSection.isSongStructure && currentLine != null) {
lines = [
...lines,
currentLine,
];
currentLine = null;
}
if (currentSection.isSongStructure && time.isNotEmpty) {}
}

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

if (currentSection.isSongStructure) {
if (_parseTimestamp(line) case KaraTime parsedTimestamp) {
if (currentStart == null ||
currentEnd == null ||
parsedTimestamp.start < currentStart) {
currentStart = parsedTimestamp.start;
currentEnd = parsedTimestamp.end;
continue;
}

time.add(parsedTimestamp);
continue;
}

if (time.isNotEmpty) {
if (currentLyric == null ||
currentStart == null ||
currentEnd == null) {
continue;
}
lines.add(KaraLine(
section: currentSection,
singers: currentSingers,
lyric: currentLyric,
start: currentStart,
end: currentEnd,
time: time,
));
time = [];
}

final parsed = _parseKeyValue(line);
if (parsed != null) {
final tempSingers = List<bool>.generate(
singers.length,
(index) => false,
growable: false,
);
parsed.value
.split(",")
.map((e) => int.tryParse(e.trim()))
.forEach((element) {
// TODO: convert number to [true,true,false]
});
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef KaraTranslation = Map<String, String>;
class KaraLine {
const KaraLine({
required this.section,
required this.singers,
this.singers,
required this.lyric,
required this.start,
required this.end,
Expand All @@ -20,7 +20,7 @@ class KaraLine {
});

final KaraSection section;
final List<bool> singers;
final List<bool>? singers;
final String lyric;
final KaraTranslation? translations;
final Duration start;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be found
// in LICENSE or at https://opensource.org/license/BSD-3-clause.

/// Mark a section of Kara file
/// Mark a section of Kara file.
enum KaraSection {
/// Contains metadata of the song.
header,
Expand Down Expand Up @@ -45,13 +45,13 @@ enum KaraSection {

/// Use to distinguish song sections.
///
/// Also check [intro], [verse], [preChorus], [chorus], [posChrous], and
/// Also check [intro], [verse], [preChorus], [chorus], [postChrous], and
/// [postBridge].
bridge,

/// Use to distinguish song sections.
///
/// Also check [intro], [verse], [preChorus], [chorus], [posChrous], and
/// Also check [intro], [verse], [preChorus], [chorus], [postChrous], and
/// [bridge].
postBridge;

Expand Down

0 comments on commit dc3447f

Please sign in to comment.