From dc3447ff79d5480a26015298ef8a9153860ec192 Mon Sep 17 00:00:00 2001 From: Brian Wo <45139213+brainwo@users.noreply.github.com> Date: Sun, 11 Aug 2024 01:45:43 +0800 Subject: [PATCH] Add documentation workflow Signed-off-by: Brian Wo <45139213+brainwo@users.noreply.github.com> --- .github/workflows/doc.yml | 40 +++++++++++++++++++++++++ .gitignore | 3 ++ lib/kara.dart | 61 +++++++++++++++++++++++++++++++-------- lib/src/line.dart | 4 +-- lib/src/section.dart | 6 ++-- 5 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/doc.yml diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml new file mode 100644 index 0000000..90f66cd --- /dev/null +++ b/.github/workflows/doc.yml @@ -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 diff --git a/.gitignore b/.gitignore index 3a85790..beca506 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ # https://dart.dev/guides/libraries/private-files # Created by `dart pub` .dart_tool/ + +# Generated doc from `dart doc` +doc/ diff --git a/lib/kara.dart b/lib/kara.dart index 2d9a6e4..885937c 100644 --- a/lib/kara.dart +++ b/lib/kara.dart @@ -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, @@ -112,10 +112,13 @@ Kara? parse(String raw) { late int year; late String album; late List languages; + Map singers = {}; KaraSection currentSection = KaraSection.header; - KaraLine? currentLine; - Map singers = {}; + List? currentSingers; + String? currentLyric; + Duration? currentStart; + Duration? currentEnd; List lines = []; List time = []; @@ -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) { @@ -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.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] + }); + } } } diff --git a/lib/src/line.dart b/lib/src/line.dart index 4404603..fcb10ec 100644 --- a/lib/src/line.dart +++ b/lib/src/line.dart @@ -11,7 +11,7 @@ typedef KaraTranslation = Map; class KaraLine { const KaraLine({ required this.section, - required this.singers, + this.singers, required this.lyric, required this.start, required this.end, @@ -20,7 +20,7 @@ class KaraLine { }); final KaraSection section; - final List singers; + final List? singers; final String lyric; final KaraTranslation? translations; final Duration start; diff --git a/lib/src/section.dart b/lib/src/section.dart index 9123375..d284c61 100644 --- a/lib/src/section.dart +++ b/lib/src/section.dart @@ -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, @@ -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;