Skip to content

Instantly share code, notes, and snippets.

@pedro-psb
Created February 6, 2024 16:29
Show Gist options
  • Save pedro-psb/b933a5abce2797b939c230b4d4020cd1 to your computer and use it in GitHub Desktop.
Save pedro-psb/b933a5abce2797b939c230b4d4020cd1 to your computer and use it in GitHub Desktop.
Create pulp-docs structure, convert to markdown and do some conversion cleaning
#!/bin/bash
# 1. create structure
mkdir -p \
staging_docs/{admin,user,dev}/{guides,tutorials,learn} \
staging_docs/reference
cp -r docs tmp_docs
# 2. convert to rst->markdown (optional)
pip install rst-to-myst[sphinx]
find tmp_docs -name '*.rst' -exec rst2myst convert --replace-files {} ';'
# 3. extra automated cleaning
DOCDIR=tmp_docs
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/:::{note}/!!! note/' {} ';'
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/:::{tip}/!!! tip/' {} ';'
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/:::{warning}/!!! warning/' {} ';'
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/:::{hint}/!!! tip/' {} ';'
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/:::{glossary}//' {} ';'
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/{term}//' {} ';'
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/{github}//' {} ';'
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/{ref}//' {} ';'
find $DOCDIR -type f -name "*.md" -exec sed -i -re 's/^\([a-zA-Z-]+\)=$//' {} ';' # remove (something)=
find $DOCDIR -type f -name "*.md" -exec sed -i -re 's/`([a-zA-Z ]*)<\w*>`/`\1`/' {} ';' # remove `some thing <RemoveThis>`
find $DOCDIR -type f -name "*.md" -exec sed -i -e 's/:::$//' {} ';'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment