From bf6593656c1ec621ae9a35df8bf5e76332b50207 Mon Sep 17 00:00:00 2001 From: mshio Date: Sat, 13 Apr 2019 01:31:40 +0000 Subject: [PATCH] Add a document generating script. git-svn-id: svn+ssh://svn.osdn.net/svnroot/sawarabi-fonts/trunk@159 54a90f34-5e62-402c-8eae-46c47f0b2e07 --- html/bin/gen.py | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ html/css/style.css | 34 +++++++------- html/en.txt | 64 ++++++++++++++++++++++++++ html/ja.txt | 63 +++++++++++++++++++++++++ html/template.html | 61 +++++++++++++++++++++++++ 5 files changed, 337 insertions(+), 17 deletions(-) create mode 100644 html/bin/gen.py create mode 100644 html/en.txt create mode 100644 html/ja.txt create mode 100644 html/template.html diff --git a/html/bin/gen.py b/html/bin/gen.py new file mode 100644 index 00000000..c2f42cd1 --- /dev/null +++ b/html/bin/gen.py @@ -0,0 +1,132 @@ +import argparse +import re +import lxml.html as html +import markdown + +class Section: + def __init__(self, name: str): + self._name = name + self._buffer = [] + self._html = None + + def append(self, line: str): + self._buffer.append(line) + + @property + def buffer(self) -> str: + if not self._html: + buf = "\n".join(self._buffer) + self._html = markdown.markdown(buf) + + return self._html + + @property + def name(self) -> str: + return self._name + +class Document: + def __init__(self): + self._props = {} + self._items = {} + + @property + def property(self) -> dict: + return self._props + + def __getitem__(self, key: str) -> dict: + return self._items[key] + + def __setitem__(self, key: str, value: str): + self._items[key] = value + + def __str__(self) -> str: + d = dict({'property': self._props}, **self._items) + return str(d) + +class Parser: + def __init__(self, clazz, rules = {}): + self._item_class = clazz + self._doc = Document() + self._item = None + self.rules = { + re.compile(v): getattr(self, k) for k, v in rules.items() + } + + def parse(self, lines): + for line in lines: + self._parse_line(line) + self.flash() + + return self._doc + + def flash(self): + if self._item: + self._doc[self._item.name] = self._item.buffer + + def on_property(self, buf: tuple): + key, value = buf + self._doc.property[key] = value + + def on_section_title(self, value: tuple): + title = value[0] + self.flash() + self._item = self._item_class(title) + + def on_content(self, value: tuple): + content = value[0] + if self._item: + self._item.append(content) + + def _parse_line(self, line: str): + def apply(k: str, v: str): + m = k.fullmatch(line) + return v(m.groups()) if m else None + + for k, v in self.rules.items(): + apply(k, v) + +rules = { + 'on_section_title': r'%\s*(.+?)\s*%*\n?', + 'on_property': r'=\((.+?)\)\s*(.+?)\s*=*\n?', + 'on_content': r'([^%=].*)\n?', +} + +def convert_sections(lines: list): + p = Parser(Section).parse(lines) + sections = p.buffer + return sections + +def parse_args(): + ps = argparse.ArgumentParser() + ps.add_argument("source") + ps.add_argument("-o", dest="out_path", default="out.html") + ps.add_argument("-t", dest="template_path", default="template.html") + + return ps.parse_args() + +if __name__ == "__main__": + args = parse_args() + print(args.source) + print(args.out_path) + print(args.template_path) + + with open(args.source) as f: + lines = f.readlines() + doc = Parser(Section, rules).parse(lines) + + print(doc) + + temp = html.parse(args.template_path) + temp.getroot().attrib['lang'] = doc.property['lang'] + temp.xpath('//title')[0].text = doc.property['title'] + img = temp.xpath('//div[contains(@class, "logo")]/img')[0] + img.attrib['src'] = f"/img/logo-{doc.property['lang']}" + img.attrib['alt'] = doc.property['title'] + + for sec in temp.xpath('//section'): + id = sec.attrib['id'] + fg = html.fromstring(doc[id]) + sec.append(fg) + + with open(args.out_path, 'w') as f: + f.write(html.tostring(temp, encoding='utf-8').decode()) diff --git a/html/css/style.css b/html/css/style.css index f844ce8f..5c9cc34a 100644 --- a/html/css/style.css +++ b/html/css/style.css @@ -2,28 +2,28 @@ body { background-color: #fff; margin: 0; } -header .container { width: 100%; } -header .container div#navbar { +nav .container { width: 100%; } +nav .container div#navbar { width: 680px; height: 66px; margin: 0 auto; background-color: #fff; } -header .container div#navbar div { float: left; } -header .container div#navbar div.logo { +nav .container div#navbar div { float: left; } +nav .container div#navbar div.logo { padding-top: 7px; } -header .container div#navbar div#lang { +nav .container div#navbar div#lang { float: right; } -header .container div#navbar div#lang div.container { +nav .container div#navbar div#lang div.container { position: absolute; top: 66px; width: 110px; display: none; box-shadow: 1px 2px 2px #000; } -header .container div#navbar div#lang div.item { +nav .container div#navbar div#lang div.item { padding: 26px 1em 0 1em; width: 80px; height: 40px; @@ -31,32 +31,32 @@ header .container div#navbar div#lang div.item { background-color: #fff; font-size: 90%; } -header .container div#navbar div#lang div.item:hover { +nav .container div#navbar div#lang div.item:hover { background-color: #c8c8c8; } -header .container div#navbar div#lang div#current-lang { +nav .container div#navbar div#lang div#current-lang { text-align: center; } -div#docs-header { +header { background-color: #084; width: 100%; height: 300px; } -div#docs-header .container { +header .container { width: 680px; height: 300px; margin: 0 auto; background-color: #0a4; } -div#docs-header .container .buttons-container { +header .container .buttons-container { position: absolute; } -div#docs-header .container .buttons-container .inner-container { +header .container .buttons-container .inner-container { position: relative; left: 600px; top: 15px; } -div#docs-header .container .buttons-container .button { +header .container .buttons-container .button { padding: .25em .55em; background-color: #fff; border-radius: 0.55em; @@ -66,17 +66,17 @@ div#docs-header .container .buttons-container .button { margin: 1px 2px; cursor: pointer; } -div#docs-header .container .buttons-container .pressed { +header .container .buttons-container .pressed { background-color: #c8c8c8; } -div#docs .container { +article .container { width: 650px; margin: 0 auto; padding: 10px 15px; background-color: #fff; font-size: 90%; } -article h2 { +section h2 { color: #094; padding-top: 1em; font-size: 125%; diff --git a/html/en.txt b/html/en.txt new file mode 100644 index 00000000..d1d1997e --- /dev/null +++ b/html/en.txt @@ -0,0 +1,64 @@ +=(title) Sawarabi Fonts = +=(language) English = +=(lang) en = + +% about +## About Sawarabi Fonts + +Sawarabi Fonts are Japanese font families which are make up of two fonts, +gothic and mincho. Sawarabi Gothic is a ‘Japanese gothic’ font, which is +similar to sans-serif. Sawarabi Mincho is a ‘mincho’ font. ‘Mincho’ means a +Ming typeface and is used like a serif font in Japan. + +Sawarabi Gothic and Mincho are normal ordinary fonts and have not notable +features. But it can be said that their design concept might be a little +traditional (or old fashioned), if compared with +[VL Gothic](http://dicey.org/vlgothic/) (or [M+ FONTS](https://mplus-fonts.osdn.jp/)) +which have already been popular as free Japanese fonts. + +Though both of fonts are available, they have not yet enough characters for +daily use, such as standard kanji, for being under developing now. + +% license +## License + +The license of Sawarabi Fonts is Creative Commons Attribution 3.0. You can see +the content of this license on the following site: + +- [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/) + +% samples +## Samples + +Sawarabi Gothic (ver.20161015). + +Sample (Gothic)
+ +Sawarabi Mincho (ver.20140815). + +Sample (Mincho)
+ +% download +## Download + +You can download the latest Sawarabi Fonts from the following links: + +
+ + +
+ +% links +## Links + +
+
Sawarabi Fonts Project Top Page
+
+The project site in OSDN. In wiki pages of it, you can get a little more +information, but these might be written in Japanese. +
+
diff --git a/html/ja.txt b/html/ja.txt new file mode 100644 index 00000000..aa1ac79e --- /dev/null +++ b/html/ja.txt @@ -0,0 +1,63 @@ +=(title) さわらびフォント = +=(language) 日本語 = +=(lang) ja = + +% about +## 概要 + + さわらびフォントは、フリーなライセンスで提供している日本語フォントです。 +現在、ゴシック体のさわらびゴシックと明朝体のさわらび明朝の 2 種類のフォントを +公開しています。 + + なお、公開しているとはいえ、現在のところどちらのフォントも開発中という段階 +です。残念ながら、現状では通常用途に必要な漢字なども十分には揃っていません +(ない文字は、ご利用の OS によっては自動補完が働き、別フォントで表示されるか +と思います)。ご利用の際はあらかじめご了承ください。 + +% license +## ライセンス + + さわらびフォントのライセンスは、Creative Commons Attribution 3.0 です。 +このライセンスの内容は、以下のリンクからご覧いただけます。 + +- [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/deed.ja) + +% samples +## 書体見本 + + さわらびゴシック(ver.20161015)の書体見本です。 + +書体見本(ゴシック)
+ + さわらび明朝(ver.20140815)の書体見本です。 + +書体見本(明朝)
+ +% download +## ダウンロード + + 下のリンクから各フォントをダウンロードすることができます。なお、さわらび +ゴシックが sawarabi-gothic、さわらび明朝が sawarabi-mincho に対応しています。 + +
+ + +
+ +% links +## Links + +
+
さわらびフォントの +プロジェクトページ
+
+OSDN 内に設置させていただいているプロジェクトページです。こちらの Wiki 文書など +に、さわらびフォントに関する、その他の情報が若干掲載されています。また、 +フォーラムもございますので、何かございましたらお寄せください。 +
+
diff --git a/html/template.html b/html/template.html new file mode 100644 index 00000000..4889495e --- /dev/null +++ b/html/template.html @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+ + + + -- 2.11.0