Skip to content

Commit 14b3ec4

Browse files
committed
#87: add version into the document
1 parent c9838af commit 14b3ec4

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

.github/workflows/document.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v2
16-
- name: Set branch name
17-
id: branch
18-
run: echo "::set-output name=BRANCH_NAME::${GITHUB_REF##*/}"
16+
- name: Set version name
17+
id: version
18+
run: echo "::set-output name=VERSION_NAME::${GITHUB_REF##*/}"
1919
- name: Set up Python 3.7
2020
uses: actions/setup-python@v2
2121
with:
@@ -27,7 +27,7 @@ jobs:
2727
- name: Generate documents (and remove markdown)
2828
run: |
2929
cd tools &&
30-
./generate_document.py &&
30+
./generate_document.py --tag ${{ steps.branch.outputs.VERSION_NAME }} &&
3131
rm ../document_ja/*.md ../document_en/*.md &&
3232
mkdir generated &&
3333
mv ../document_ja generated/ &&
@@ -37,4 +37,4 @@ jobs:
3737
with:
3838
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
3939
publish_dir: ./tools/generated
40-
destination_dir: ${{ steps.branch.outputs.BRANCH_NAME }}
40+
destination_dir: ${{ steps.branch.outputs.VERSION_NAME }}

document_en/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# AC(AtCoder) Library Document
1+
# AC(AtCoder) Library Document (@{keyword.tag})
2+
3+
@{keyword.info}
24

35
## How to Install
46

document_en/keywords.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
constraints = 'Constraints'
22
complexity = 'Complexity'
33
examples = 'Examples'
4+
info = '*The version of this document may differ from the one which is installed in AtCoder, AtCoder-installed version is [here](https://atcoder.github.io/ac-library/production/document_ja/).*'

document_ja/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# AC(AtCoder) Library Document
1+
# AC(AtCoder) Library Document (@{keyword.tag})
2+
3+
@{keyword.info}
24

35
## インストール方法
46

document_ja/keywords.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
constraints = '制約'
22
complexity = '計算量'
33
examples = '使用例'
4+
info = '*このドキュメントの内容は AtCoder にインストールされているものとバージョンが異なる可能性があります。 AtCoder にインストールされているバージョンは [こちら](https://atcoder.github.io/ac-library/production/document_ja/) を参照してください*'

tools/generate_document.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from logging import Logger, basicConfig, getLogger
44
from os import getenv
5+
import argparse
6+
import re
57
from pathlib import Path
68

79
import markdown
@@ -42,8 +44,11 @@ def __getitem__(self, key: str):
4244
html_head = open('template_head.html', 'r').read()
4345
html_body = open('template_body.html', 'r').read()
4446

45-
def convert(md_statement: str, base_dir: Path) -> str:
47+
def convert(md_statement: str, base_dir: Path, tag: str) -> str:
4648
keywords = toml.load(base_dir / 'keywords.toml')
49+
keywords['tag'] = tag
50+
if tag == 'production' or re.match(r'v[0-9]\.[0-9]', tag):
51+
keywords['info'] = ''
4752

4853
environment = Environment(
4954
variable_start_string="@{", variable_end_string="}", loader=DictLoader({'task': md_statement}))
@@ -70,6 +75,9 @@ def convert(md_statement: str, base_dir: Path) -> str:
7075
datefmt="%H:%M:%S",
7176
level=getenv('LOG_LEVEL', 'INFO'),
7277
)
78+
parser = argparse.ArgumentParser(description='Document generator')
79+
parser.add_argument('--tag', help='Library version')
80+
opts = parser.parse_args()
7381

7482
langs = ['en', 'ja']
7583
for lang in langs:
@@ -78,7 +86,7 @@ def convert(md_statement: str, base_dir: Path) -> str:
7886

7987
for md_file in base_dir.glob('*.md'):
8088
logger.info('convert {}'.format(md_file))
81-
statement = convert(open(md_file).read(), base_dir)
89+
statement = convert(open(md_file).read(), base_dir, opts.tag)
8290

8391
html_file = base_dir / (md_file.stem + '.html')
8492
with open(html_file, 'w') as f:

0 commit comments

Comments
 (0)