• R/O
  • SSH
  • HTTPS

sawarabi-fonts: コミット


コミットメタ情報

リビジョン159 (tree)
日時2019-04-13 10:31:40
作者mshio

ログメッセージ

Add a document generating script.

変更サマリ

差分

--- trunk/html/bin/gen.py (nonexistent)
+++ trunk/html/bin/gen.py (revision 159)
@@ -0,0 +1,132 @@
1+import argparse
2+import re
3+import lxml.html as html
4+import markdown
5+
6+class Section:
7+ def __init__(self, name: str):
8+ self._name = name
9+ self._buffer = []
10+ self._html = None
11+
12+ def append(self, line: str):
13+ self._buffer.append(line)
14+
15+ @property
16+ def buffer(self) -> str:
17+ if not self._html:
18+ buf = "\n".join(self._buffer)
19+ self._html = markdown.markdown(buf)
20+
21+ return self._html
22+
23+ @property
24+ def name(self) -> str:
25+ return self._name
26+
27+class Document:
28+ def __init__(self):
29+ self._props = {}
30+ self._items = {}
31+
32+ @property
33+ def property(self) -> dict:
34+ return self._props
35+
36+ def __getitem__(self, key: str) -> dict:
37+ return self._items[key]
38+
39+ def __setitem__(self, key: str, value: str):
40+ self._items[key] = value
41+
42+ def __str__(self) -> str:
43+ d = dict({'property': self._props}, **self._items)
44+ return str(d)
45+
46+class Parser:
47+ def __init__(self, clazz, rules = {}):
48+ self._item_class = clazz
49+ self._doc = Document()
50+ self._item = None
51+ self.rules = {
52+ re.compile(v): getattr(self, k) for k, v in rules.items()
53+ }
54+
55+ def parse(self, lines):
56+ for line in lines:
57+ self._parse_line(line)
58+ self.flash()
59+
60+ return self._doc
61+
62+ def flash(self):
63+ if self._item:
64+ self._doc[self._item.name] = self._item.buffer
65+
66+ def on_property(self, buf: tuple):
67+ key, value = buf
68+ self._doc.property[key] = value
69+
70+ def on_section_title(self, value: tuple):
71+ title = value[0]
72+ self.flash()
73+ self._item = self._item_class(title)
74+
75+ def on_content(self, value: tuple):
76+ content = value[0]
77+ if self._item:
78+ self._item.append(content)
79+
80+ def _parse_line(self, line: str):
81+ def apply(k: str, v: str):
82+ m = k.fullmatch(line)
83+ return v(m.groups()) if m else None
84+
85+ for k, v in self.rules.items():
86+ apply(k, v)
87+
88+rules = {
89+ 'on_section_title': r'%\s*(.+?)\s*%*\n?',
90+ 'on_property': r'=\((.+?)\)\s*(.+?)\s*=*\n?',
91+ 'on_content': r'([^%=].*)\n?',
92+}
93+
94+def convert_sections(lines: list):
95+ p = Parser(Section).parse(lines)
96+ sections = p.buffer
97+ return sections
98+
99+def parse_args():
100+ ps = argparse.ArgumentParser()
101+ ps.add_argument("source")
102+ ps.add_argument("-o", dest="out_path", default="out.html")
103+ ps.add_argument("-t", dest="template_path", default="template.html")
104+
105+ return ps.parse_args()
106+
107+if __name__ == "__main__":
108+ args = parse_args()
109+ print(args.source)
110+ print(args.out_path)
111+ print(args.template_path)
112+
113+ with open(args.source) as f:
114+ lines = f.readlines()
115+ doc = Parser(Section, rules).parse(lines)
116+
117+ print(doc)
118+
119+ temp = html.parse(args.template_path)
120+ temp.getroot().attrib['lang'] = doc.property['lang']
121+ temp.xpath('//title')[0].text = doc.property['title']
122+ img = temp.xpath('//div[contains(@class, "logo")]/img')[0]
123+ img.attrib['src'] = f"/img/logo-{doc.property['lang']}"
124+ img.attrib['alt'] = doc.property['title']
125+
126+ for sec in temp.xpath('//section'):
127+ id = sec.attrib['id']
128+ fg = html.fromstring(doc[id])
129+ sec.append(fg)
130+
131+ with open(args.out_path, 'w') as f:
132+ f.write(html.tostring(temp, encoding='utf-8').decode())
--- trunk/html/css/style.css (revision 158)
+++ trunk/html/css/style.css (revision 159)
@@ -2,21 +2,21 @@
22 background-color: #fff;
33 margin: 0;
44 }
5-header .container { width: 100%; }
6-header .container div#navbar {
5+nav .container { width: 100%; }
6+nav .container div#navbar {
77 width: 680px;
88 height: 66px;
99 margin: 0 auto;
1010 background-color: #fff;
1111 }
12-header .container div#navbar div { float: left; }
13-header .container div#navbar div.logo {
12+nav .container div#navbar div { float: left; }
13+nav .container div#navbar div.logo {
1414 padding-top: 7px;
1515 }
16-header .container div#navbar div#lang {
16+nav .container div#navbar div#lang {
1717 float: right;
1818 }
19-header .container div#navbar div#lang div.container {
19+nav .container div#navbar div#lang div.container {
2020 position: absolute;
2121 top: 66px;
2222 width: 110px;
@@ -23,7 +23,7 @@
2323 display: none;
2424 box-shadow: 1px 2px 2px #000;
2525 }
26-header .container div#navbar div#lang div.item {
26+nav .container div#navbar div#lang div.item {
2727 padding: 26px 1em 0 1em;
2828 width: 80px;
2929 height: 40px;
@@ -31,32 +31,32 @@
3131 background-color: #fff;
3232 font-size: 90%;
3333 }
34-header .container div#navbar div#lang div.item:hover {
34+nav .container div#navbar div#lang div.item:hover {
3535 background-color: #c8c8c8;
3636 }
37-header .container div#navbar div#lang div#current-lang {
37+nav .container div#navbar div#lang div#current-lang {
3838 text-align: center;
3939 }
40-div#docs-header {
40+header {
4141 background-color: #084;
4242 width: 100%;
4343 height: 300px;
4444 }
45-div#docs-header .container {
45+header .container {
4646 width: 680px;
4747 height: 300px;
4848 margin: 0 auto;
4949 background-color: #0a4;
5050 }
51-div#docs-header .container .buttons-container {
51+header .container .buttons-container {
5252 position: absolute;
5353 }
54-div#docs-header .container .buttons-container .inner-container {
54+header .container .buttons-container .inner-container {
5555 position: relative;
5656 left: 600px;
5757 top: 15px;
5858 }
59-div#docs-header .container .buttons-container .button {
59+header .container .buttons-container .button {
6060 padding: .25em .55em;
6161 background-color: #fff;
6262 border-radius: 0.55em;
@@ -66,10 +66,10 @@
6666 margin: 1px 2px;
6767 cursor: pointer;
6868 }
69-div#docs-header .container .buttons-container .pressed {
69+header .container .buttons-container .pressed {
7070 background-color: #c8c8c8;
7171 }
72-div#docs .container {
72+article .container {
7373 width: 650px;
7474 margin: 0 auto;
7575 padding: 10px 15px;
@@ -76,7 +76,7 @@
7676 background-color: #fff;
7777 font-size: 90%;
7878 }
79-article h2 {
79+section h2 {
8080 color: #094;
8181 padding-top: 1em;
8282 font-size: 125%;
--- trunk/html/en.txt (nonexistent)
+++ trunk/html/en.txt (revision 159)
@@ -0,0 +1,64 @@
1+=(title) Sawarabi Fonts =
2+=(language) English =
3+=(lang) en =
4+
5+% about
6+## About Sawarabi Fonts
7+
8+Sawarabi Fonts are Japanese font families which are make up of two fonts,
9+gothic and mincho. Sawarabi Gothic is a ‘Japanese gothic’ font, which is
10+similar to sans-serif. Sawarabi Mincho is a ‘mincho’ font. ‘Mincho’ means a
11+Ming typeface and is used like a serif font in Japan.
12+
13+Sawarabi Gothic and Mincho are normal ordinary fonts and have not notable
14+features. But it can be said that their design concept might be a little
15+traditional (or old fashioned), if compared with
16+[VL Gothic](http://dicey.org/vlgothic/) (or [M+ FONTS](https://mplus-fonts.osdn.jp/))
17+which have already been popular as free Japanese fonts.
18+
19+Though both of fonts are available, they have not yet enough characters for
20+daily use, such as standard kanji, for being under developing now.
21+
22+% license
23+## License
24+
25+The license of Sawarabi Fonts is Creative Commons Attribution 3.0. You can see
26+the content of this license on the following site:
27+
28+- [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/)
29+
30+% samples
31+## Samples
32+
33+Sawarabi Gothic (ver.20161015).
34+
35+<img src="/img/sample-gothic.png" alt="Sample (Gothic)" /><br />
36+
37+Sawarabi Mincho (ver.20140815).
38+
39+<img src="../img/sample-mincho.png" alt="Sample (Mincho)" /><br />
40+
41+% download
42+## Download
43+
44+You can download the latest Sawarabi Fonts from the following links:
45+
46+<div id="download-box">
47+<script charset="utf-8" type="text/javascript" src="https://osdn.net/projects/sawarabi-fonts/files/compact.js"></script>
48+<noscript>
49+<p style="border: 1px solid black">
50+(The download links cannot be shown because your browser disable JavaScript.
51+Please download them from <a href="https://osdn.net/projects/sawarabi-fonts/">Sawarabi Fonts Project site</a>.)</p>
52+</noscript>
53+</div>
54+
55+% links
56+## Links
57+
58+<dl>
59+<dt><a href="https://osdn.net/projects/sawarabi-fonts/">Sawarabi Fonts Project Top Page</a></dt>
60+<dd>
61+The project site in OSDN. In wiki pages of it, you can get a little more
62+information, but these might be written in Japanese.
63+</dd>
64+</dl>
--- trunk/html/ja.txt (nonexistent)
+++ trunk/html/ja.txt (revision 159)
@@ -0,0 +1,63 @@
1+=(title) さわらびフォント =
2+=(language) 日本語 =
3+=(lang) ja =
4+
5+% about
6+## 概要
7+
8+ さわらびフォントは、フリーなライセンスで提供している日本語フォントです。
9+現在、ゴシック体のさわらびゴシックと明朝体のさわらび明朝の 2 種類のフォントを
10+公開しています。
11+
12+ なお、公開しているとはいえ、現在のところどちらのフォントも開発中という段階
13+です。残念ながら、現状では通常用途に必要な漢字なども十分には揃っていません
14+(ない文字は、ご利用の OS によっては自動補完が働き、別フォントで表示されるか
15+と思います)。ご利用の際はあらかじめご了承ください。
16+
17+% license
18+## ライセンス
19+
20+ さわらびフォントのライセンスは、Creative Commons Attribution 3.0 です。
21+このライセンスの内容は、以下のリンクからご覧いただけます。
22+
23+- [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/deed.ja)
24+
25+% samples
26+## 書体見本
27+
28+ さわらびゴシック(ver.20161015)の書体見本です。
29+
30+<img src="/img/sample-gothic.png" alt="書体見本(ゴシック)" /><br />
31+
32+ さわらび明朝(ver.20140815)の書体見本です。
33+
34+<img src="/img/sample-mincho.png" alt="書体見本(明朝)" /><br />
35+
36+% download
37+## ダウンロード
38+
39+ 下のリンクから各フォントをダウンロードすることができます。なお、さわらび
40+ゴシックが sawarabi-gothic、さわらび明朝が sawarabi-mincho に対応しています。
41+
42+<div id="download-box">
43+<script charset="utf-8" type="text/javascript" src="https://osdn.net/projects/sawarabi-fonts/files/compact.js"></script>
44+<noscript>
45+<p style="border: 1px solid black"> (JavaScript が有効になっていない場合は、
46+ここにリンクは現れません。
47+ダウンロードは <a href="https://osdn.net/projects/sawarabi-fonts/">OSDN
48+のプロジェクトページ</a>から行ってください。)</p>
49+</noscript>
50+</div>
51+
52+% links
53+## Links
54+
55+<dl>
56+<dt><a href="https://osdn.net/projects/sawarabi-fonts/">さわらびフォントの
57+プロジェクトページ</a></dt>
58+<dd>
59+OSDN 内に設置させていただいているプロジェクトページです。こちらの Wiki 文書など
60+に、さわらびフォントに関する、その他の情報が若干掲載されています。また、
61+フォーラムもございますので、何かございましたらお寄せください。
62+</dd>
63+</dl>
--- trunk/html/template.html (nonexistent)
+++ trunk/html/template.html (revision 159)
@@ -0,0 +1,61 @@
1+<!DOCTYPE html>
2+<html>
3+ <head>
4+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5+ <title></title>
6+ <link rel="stylesheet" href="css/style.css" type="text/css" />
7+ <script src="js/mobile.js" type="text/javascript"></script>
8+ <script src="js/jquery-2.1.0.min.js" type="text/javascript"></script>
9+ <script src="js/lang.js" type="text/javascript"></script>
10+ <script src="js/doc-header/ja.js" type="text/javascript"></script>
11+ <script src="js/doc-header.js" type="text/javascript"></script>
12+ </head>
13+ <body>
14+ <nav>
15+ <div class="container">
16+ <div id="navbar">
17+ <div class="logo"><img src="img/logo-en.png" alt="Sawarabi Fonts" /></div>
18+ <div id="lang">
19+ <div id="current-lang" class="item" title="Select your language">English</div>
20+ <div id="lang-menu-container" class="container">
21+ </div>
22+ </div>
23+ </div>
24+ <div style="clear: both;"></div>
25+ </div>
26+ </nav>
27+
28+ <header>
29+ <div class="container">
30+ <div class="buttons-container"><div class="inner-container"></div></div>
31+ <canvas id="header-canvas" width="680" height="300"></canvas>
32+ </div>
33+ </header>
34+
35+ <article id="docs">
36+ <div class="container">
37+
38+ <section id="about">
39+ </section>
40+
41+ <section id="license">
42+ </section>
43+
44+ <section id="samples">
45+ </section>
46+
47+ <section id="download">
48+ </section>
49+
50+ <section id="links">
51+ </section>
52+ </div>
53+ </article>
54+
55+ <footer>
56+ <div class="container">
57+ <a href="https://osdn.net/"><img src="//osdn.net/sflogo.php?group_id=3896&amp;type=1" width="96" height="31" alt="OSDN" /></a>
58+ </div>
59+ </footer>
60+ </body>
61+</html>
旧リポジトリブラウザで表示