Skip to content

Commit 6d58ad8

Browse files
authored
Merge pull request #99 from atcoder/patch/issue87
#87: add version into the document
2 parents 752830c + dfdd94d commit 6d58ad8

File tree

7 files changed

+35
-45
lines changed

7 files changed

+35
-45
lines changed

.github/workflows/artifact.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/document.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
11
name: Document
22

3-
on:
4-
push:
5-
branches:
6-
- master
7-
- production
8-
tags:
9-
- 'v*'
3+
on: [push, pull_request]
104

115
jobs:
126
doc:
137
runs-on: ubuntu-latest
148
steps:
159
- uses: actions/checkout@v2
16-
- name: Set branch name
17-
id: branch
18-
run: echo "::set-output name=BRANCH_NAME::${GITHUB_REF##*/}"
19-
- name: Set up Python 3.7
10+
- name: Set version name
11+
id: version
12+
run: echo "::set-output name=VERSION_NAME::${GITHUB_REF##*/}"
13+
- name: Set up Python 3.9
2014
uses: actions/setup-python@v2
2115
with:
22-
python-version: 3.7
16+
python-version: 3.9
2317
- name: Install dependencies
2418
run: |
2519
python -m pip install --upgrade pip
2620
pip install --user -r tools/requirements.txt
2721
- name: Generate documents (and remove markdown)
2822
run: |
2923
cd tools &&
30-
./generate_document.py &&
24+
./generate_document.py --tag $VERSION &&
25+
./generate_zip.py &&
3126
rm ../document_ja/*.md ../document_en/*.md &&
3227
mkdir generated &&
3328
mv ../document_ja generated/ &&
3429
mv ../document_en generated/
30+
env:
31+
VERSION: ${{ steps.version.outputs.VERSION_NAME }}
3532
- name: Publish to github pages
33+
if: ${{ github.event_name == 'push' }}
3634
uses: peaceiris/actions-gh-pages@v3
3735
with:
3836
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
3937
publish_dir: ./tools/generated
40-
destination_dir: ${{ steps.branch.outputs.BRANCH_NAME }}
38+
destination_dir: ${{ steps.version.outputs.VERSION_NAME }}
39+
- name: Upload zip
40+
uses: actions/upload-artifact@v2
41+
with:
42+
name: ac-library
43+
path: tools/ac-library.zip

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)