Skip to content

Commit

Permalink
Added jobs for publishing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Meyer committed Nov 13, 2021
1 parent 8a68dae commit 90225ed
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish Documentation
on:
push:
branches: [ develop ]
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Process files
run: |
python scripts/publish-docs.py
- name: Upload FTP
uses: sebastianpopp/ftp-action@releases/v2
with:
host: ${{ secrets.FTP_SERVER }}
user: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
localDir: "processed-docs"
remoteDir: "."
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/
venv
processed-docs/
60 changes: 60 additions & 0 deletions scripts/publish-docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import re
from os import listdir
from os import makedirs
from os.path import abspath
from os.path import basename
from os.path import dirname
from os.path import isfile
from os.path import join

CURRENT_DIR = dirname(abspath(__file__))

INPUT_DIR = join(join(CURRENT_DIR, '..'), 'docs')
OUTPUT_DIR = join(join(CURRENT_DIR, '..'), 'processed-docs')


def main():
makedirs(OUTPUT_DIR, exist_ok=True)
markdown_files = _get_markdown_files()

for in_file in markdown_files:
out_file = _get_processed_file_name(in_file)

with open(in_file, 'r') as ifp:
with open(out_file, 'w') as ofp:
while True:
line = ifp.readline()
if not line:
break
ofp.write(_process_line(line))


def _get_markdown_files():
files = [
join(INPUT_DIR, file)
for file in listdir(INPUT_DIR)
]
return [
file
for file in files
if isfile(file) and file.endswith('.md')
]


def _get_processed_file_name(in_file):
return join(OUTPUT_DIR, basename(in_file))


def _process_line(line):
# Process markdown links to other markdown files
result = re.sub(r'(\[[^]]+]\([^)]+)\.md([^)]*\))', r'\1\2', line)
# Process markdown image references
result = re.sub(r'(!\[[^]]+]\()\.\.(/assets/[^)]+\))', r'\1\2', result)
# Process HTML image references
result = re.sub(r'( src=")\.\.(/assets/[^"]+")', r'\1\2', result)

return result


if __name__ == '__main__':
main()

0 comments on commit 90225ed

Please sign in to comment.