From ba21dae98542b89e6b7c04ddd8ec1b262d814c5b Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 17 Dec 2022 18:02:28 +0800 Subject: [PATCH] feat: markdown release function --- src/release/{to-json.py => to_json.py} | 0 src/release/to_markdown.py | 31 ++++++++++++++++++++++++++ src/release/{to-txt.py => to_txt.py} | 0 3 files changed, 31 insertions(+) rename src/release/{to-json.py => to_json.py} (100%) create mode 100644 src/release/to_markdown.py rename src/release/{to-txt.py => to_txt.py} (100%) diff --git a/src/release/to-json.py b/src/release/to_json.py similarity index 100% rename from src/release/to-json.py rename to src/release/to_json.py diff --git a/src/release/to_markdown.py b/src/release/to_markdown.py new file mode 100644 index 0000000..31f632b --- /dev/null +++ b/src/release/to_markdown.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import sys +from common import loadData + + +def formatMetadata(metadata: dict) -> str: + return '# %s\n\n+ 作者:%s\n\n> %s' % ( + metadata['name'], + metadata['author'], + '\n> '.join(metadata['desc']), + ) + + +def formatChapter(caption: str, content: list) -> str: + return '## %s\n\n%s' % (caption, '\n\n'.join(content)) + + +def markdownRelease(metadata: dict, content: dict) -> str: + result = [formatMetadata(metadata)] + for (title, chapter) in content.items(): + result.append( + formatChapter(title, chapter) + ) + return '\n\n'.join(result) + + +if __name__ == '__main__': + data = loadData(sys.argv[1]) + print(markdownRelease(data['metadata'], data['content'])) diff --git a/src/release/to-txt.py b/src/release/to_txt.py similarity index 100% rename from src/release/to-txt.py rename to src/release/to_txt.py