Skip to content
Permalink
Browse files

Convert the wiki with mdBook

  • Loading branch information
nickelc committed Nov 28, 2019
1 parent dbfa983 commit 9651ada586ae8c20b6c6691c1ed4c91cea11a53e
Showing with 77 additions and 10 deletions.
  1. +9 −10 .github/workflows/release.yml
  2. +4 −0 .gitignore
  3. +9 −0 book/book.toml
  4. +55 −0 book/linkfix.py
@@ -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
@@ -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 -r ../docs.zip docs/*
- name: Upload
uses: actions/upload-release-asset@v1.0.1
@@ -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
@@ -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"
@@ -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 9651ada

Please sign in to comment.
You can’t perform that action at this time.