Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Convert the wiki with mdBook
Browse files Browse the repository at this point in the history
  • Loading branch information
nickelc committed Nov 30, 2019
1 parent dbfa983 commit e3da194
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 10 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/release.yml
Expand Up @@ -104,10 +104,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Install packages
run: |
sudo apt-get install python3-pip
sudo pip install grip
- name: Install mdBook
uses: peaceiris/actions-mdbook@v1

- name: Checkout
uses: actions/checkout@v1
Expand All @@ -120,12 +118,13 @@ jobs:

- name: Build
run: |
mkdir -p docs
rename.ul '::' '__' ../SDK.wiki/*
./.github/workflows/convert-docs.sh ../SDK.wiki ./docs ${{ secrets.GITHUB_TOKEN }}
zip docs.zip docs/*
mkdir -p book/src
cp ../SDK.wiki/*.md book/src/
rename.ul '::' '__' book/src/*
cd book
cat src/_Sidebar.md | ./linkfix.py summary > src/SUMMARY.md
mdbook build -d docs
zip ../docs.zip docs/*
- name: Upload
uses: actions/upload-release-asset@v1.0.1
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -42,5 +42,9 @@ src/modio.lib
src/modio.exp
src/modio.a

# mdBook for release workflow
book/src
book/docs

!examples/c/mods_dir/readme.txt
!examples/c++/mods_dir/readme.txt
9 changes: 9 additions & 0 deletions book/book.toml
@@ -0,0 +1,9 @@
[book]
authors = ["Ahmed Castro <ahmed.hn.43@gmail.com>"]
language = "en"
multilingual = false
src = "src"
title = "modio SDK"

[preprocessor.linkfix]
command = "./linkfix.py"
55 changes: 55 additions & 0 deletions book/linkfix.py
@@ -0,0 +1,55 @@
#!/usr/bin/env python3
import json
import re
import sys

"""Match [[File]] and [[Title|File]]"""
WIKI_LINK = re.compile('(?:\[\[(?:(.*)\|)?(.*)\]\])')

def replace_links(content):
def repl(m):
(title, filename) = m.group(1, 2)

title = title if title else filename
filename = filename.strip().replace(' ', '-').replace('::', '__')

return "[%s](%s.md)" % (title.strip(), filename)

return WIKI_LINK.sub(repl, content)

def walk_book(section, func):
if 'Chapter' not in section:
return

content = section['Chapter']['content'];
content = func(content)
section['Chapter']['content'] = content

for section in section['Chapter']['sub_items']:
walk_book(section, func)

def main():
if len(sys.argv) > 1 and sys.argv[1] == 'supports':
exit(0)

if len(sys.argv) > 1 and sys.argv[1] == 'summary':
content = sys.stdin.buffer.read().decode('utf-8')
"""
Every chapter must contain a link.
Change every `* Foobar` to `* [[Foobar]]`.
"""
content = re.sub('\* ([A-Za-z ]+)', lambda m: "* [[%s]]" % m.group(1), content)
print(replace_links(content))
exit(0)

raw = sys.stdin.buffer.read()
[context, book] = json.loads(raw.decode('utf-8'))

for section in book['sections']:
walk_book(section, replace_links)

json.dump(book, sys.stdout)
exit(0)

if __name__ == '__main__':
main()

0 comments on commit e3da194

Please sign in to comment.