Last active
February 15, 2019 14:23
-
-
Save nottrobin/71de501f9c69e6230a5c633fb4764ed9 to your computer and use it in GitHub Desktop.
Converting juju docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get juju-docs and discoursifier | |
git clone -b devel https://github.com/juju/docs ~/git/juju-docs | |
git clone https://github.com/canonical-webteam/discoursifier ~/git/discoursifier | |
# Setup python venv for discoursifier | |
python3 -m venv ~/git/discoursifier/env3 | |
source ~/git/discoursifier/env3/bin/activate | |
pip install -r ~/git/discoursifier/requirements.txt | |
# Enter the documentation directory | |
cd ~/git/juju-docs/src/en | |
# Remove files we don't want to include in Discourse | |
rm commands.md test.md index.md | |
# Apply discoursifier conversions | |
~/git/discoursifier/convert.py | |
# Reformat with pandoc to remove newlines | |
find . -name '*.md' -exec pandoc --atx-headers -f markdown_mmd+backtick_code_blocks -t markdown_mmd+hard_line_breaks+backtick_code_blocks+shortcut_reference_links {} -o {} \; | |
# Unescape characters espaced by pandoc | |
find . -name '*.md' -exec sed -i -E 's!\\(\[|\*|\^|`|_|[(]|[)]|\$|\]|#|~)!\1!g' {} \; | |
# Fix notification blocks | |
find . -name '*.md' -exec sed -i -E 's!(\[note[^]]*\]) !\1\n!g' {} \; | |
find . -name '*.md' -exec sed -i -E 's! \[/note\]!\n[/note]!g' {} \; | |
# Replace "bash" and "no-highlight" code blocks with "text" code blocks | |
find . -name '*.md' -exec sed -i -E 's!``` (bash|no-highlight)!``` text!g' {} \; | |
# OPTIONAL - Delete all topics in the "docs-import" category | |
~/git/discoursifier/delete.py --api-key=xxxx --api-username=robin --api-url=https://discourse.jujucharms.com/ --category=docs-import | |
# Before uploading, ensure "min topic title length" is set to 5 | |
# https://discourse.jujucharms.com/admin/site_settings/category/all_results?filter=min%20topic%20title%20length | |
# Upload all documents as new topics to Discourse | |
~/git/discoursifier/upload.py --api-key=xxxx --api-username=robin --api-url=https://discourse.jujucharms.com/ --title-map=title-map.json --category=docs-import |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment