Skip to content

Commit

Permalink
#87: add version into the document
Browse files Browse the repository at this point in the history
  • Loading branch information
yosupo06 committed Jan 18, 2021
1 parent c9838af commit 14b3ec4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/document.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 13,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set branch name
id: branch
run: echo "::set-output name=BRANCH_NAME::${GITHUB_REF##*/}"
- name: Set version name
id: version
run: echo "::set-output name=VERSION_NAME::${GITHUB_REF##*/}"
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
Expand All @@ -27,7 27,7 @@ jobs:
- name: Generate documents (and remove markdown)
run: |
cd tools &&
./generate_document.py &&
./generate_document.py --tag ${{ steps.branch.outputs.VERSION_NAME }} &&
rm ../document_ja/*.md ../document_en/*.md &&
mkdir generated &&
mv ../document_ja generated/ &&
Expand All @@ -37,4 37,4 @@ jobs:
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./tools/generated
destination_dir: ${{ steps.branch.outputs.BRANCH_NAME }}
destination_dir: ${{ steps.branch.outputs.VERSION_NAME }}
4 changes: 3 additions & 1 deletion document_en/index.md
Original file line number Diff line number Diff line change
@@ -1,4 1,6 @@
# AC(AtCoder) Library Document
# AC(AtCoder) Library Document (@{keyword.tag})

@{keyword.info}

## How to Install

Expand Down
1 change: 1 addition & 0 deletions document_en/keywords.toml
Original file line number Diff line number Diff line change
@@ -1,3 1,4 @@
constraints = 'Constraints'
complexity = 'Complexity'
examples = 'Examples'
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/).*'
4 changes: 3 additions & 1 deletion document_ja/index.md
Original file line number Diff line number Diff line change
@@ -1,4 1,6 @@
# AC(AtCoder) Library Document
# AC(AtCoder) Library Document (@{keyword.tag})

@{keyword.info}

## インストール方法

Expand Down
1 change: 1 addition & 0 deletions document_ja/keywords.toml
Original file line number Diff line number Diff line change
@@ -1,3 1,4 @@
constraints = '制約'
complexity = '計算量'
examples = '使用例'
info = '*このドキュメントの内容は AtCoder にインストールされているものとバージョンが異なる可能性があります。 AtCoder にインストールされているバージョンは [こちら](https://atcoder.github.io/ac-library/production/document_ja/) を参照してください*'
12 changes: 10 additions & 2 deletions tools/generate_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,8 @@

from logging import Logger, basicConfig, getLogger
from os import getenv
import argparse
import re
from pathlib import Path

import markdown
Expand Down Expand Up @@ -42,8 44,11 @@ def __getitem__(self, key: str):
html_head = open('template_head.html', 'r').read()
html_body = open('template_body.html', 'r').read()

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

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

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

for md_file in base_dir.glob('*.md'):
logger.info('convert {}'.format(md_file))
statement = convert(open(md_file).read(), base_dir)
statement = convert(open(md_file).read(), base_dir, opts.tag)

html_file = base_dir / (md_file.stem '.html')
with open(html_file, 'w') as f:
Expand Down

0 comments on commit 14b3ec4

Please sign in to comment.