Skip to content

Commit

Permalink
build: add manual generation
Browse files Browse the repository at this point in the history
  • Loading branch information
reddec committed Jun 25, 2020
1 parent c4195c1 commit 652d196
Show file tree
Hide file tree
Showing 21 changed files with 538 additions and 19 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
with:
go-version: 1.13
id: go
- name: Install deps
run: apt install -y python3 pandoc

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -25,7 +27,12 @@ jobs:

- name: Pull tag
run: git fetch --tags

- name: Build doc
run: |
python3 assemble_md.py ./docs --exclude ./docs/vendor ./docs/.bundle ./docs/.jekyll-cache ./docs/_site > MANUAL.md
pandoc MANUAL.md -s -t man -o trusted-cgi.1
pandoc --metadata title="Trusted-CGI manual" MANUAL.md -s --include-in-header=./docs/assets/github-pandoc.css --toc -o MANUAL.html
gzip trusted-cgi.1
- uses: azure/docker-login@v1
with:
username: 'reddec'
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
/docs/Gemfile*
/docs/.bundle
/docs/_site
/docs/.jekyll-cache
/docs/.jekyll-cache
/MANUAL.md
/*.gz
/MANUAL.html
3 changes: 3 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ nfpms:
- /etc/trusted-cgi
files:
"debian/trusted-cgi.service": "/etc/systemd/system/trusted-cgi.service"
"trusted-cgi.1.gz" : "/usr/local/share/man/man1/trusted-cgi.1.gz"
config_files:
"debian/trusted-cgi.env": "/etc/trusted-cgi/trusted-cgi.env"
uploads:
Expand All @@ -88,6 +89,8 @@ archives:
files:
- LICENSE
- README.md
- MANUAL.md
- MANUAL.html
format: tar.gz
format_overrides:
- goos: windows
Expand Down
80 changes: 80 additions & 0 deletions assemble_md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import sys
import argparse


parser = argparse.ArgumentParser(description='Assembe markdown in one doc')
parser.add_argument('root_dir', type=str, help='dir to scan')
parser.add_argument('--exclude', type=str, nargs='*', help='paths to exclude')
args = parser.parse_args()


def add_level(line, depth):
if not line.startswith('#'):
return line
num = 0
title = ''
for i, x in enumerate(line):
if x == '#':
num += 1
else:
title = line[i:]
break
return '#' * (depth + num) + title

root_dir = args.root_dir
exclude = set(args.exclude or [])
for root, dirs, files in os.walk(root_dir):
ignore = False
for dir in exclude:
if root.startswith(dir):
ignore = True
break
if ignore:
continue

title = ''
root_depth = root[len(root_dir):].count(os.sep)

if root_depth == 0:
title = 'Manual'
else:
title = os.path.basename(root)

print()
print("#" * root_depth, title.title().replace('_',' '))
print()

root_depth += 1

if 'index.md' in files:
idx = files.index('index.md')
files[0], files[idx] = files[idx], files[0]

for file in files:
if not file.lower().endswith('.md'):
continue
depth = root_depth
section = file[:-3].strip()
if section == 'index':
depth += 1
else:
print()
print("#" * depth, section.title().replace('_',' '))
print()
with open(os.path.join(root, file), 'rt') as f:
line = next(f)
if line.startswith('-'):
for line in f:
if line.startswith('-'):
break
else:
print(add_level(line,depth))
for line in f:
print(add_level(line,depth))






Loading

0 comments on commit 652d196

Please sign in to comment.