Skip to content

Commit

Permalink
docs: misc core migration cleanup (#419)
Browse files Browse the repository at this point in the history
* ci: add script to handle dip processing

* fix: correct path

* chore: add markdown lint config
  • Loading branch information
thephez authored Nov 7, 2024
1 parent 13c69c0 commit 648e064
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"default": true,
"MD004": { "style": "asterisk"},
"MD013": false,
"MD033": false,
"MD036": false,
"MD040": true,
"MD041": false,
"MD049": true
}
11 changes: 11 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import os
import subprocess
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# Clone the DIPs repository and process DIPs so they are rendered properly
if not os.path.exists('_external_repo'):
subprocess.check_call(['git', 'clone', 'https://github.com/dashpay/dips.git', '_dips'])
subprocess.check_call(['./scripts/dip-format.sh'])
subprocess.check_call('cd _dips/ && find . -name ".git" -prune -o -print -exec cp --parents \{} ../docs/core/dips/ \;', shell=True)
subprocess.check_call('cd', shell=True)
subprocess.check_call('rm -rf _dips/', shell=True)

# -- General configuration ------------------------------------------------

Expand Down
69 changes: 69 additions & 0 deletions scripts/dip-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Directory containing the files
dir='_dips'

echo "Starting to process files in $dir..."

# Add start of toctree
content=$(cat <<EOL
\`\`\`{toctree}
:maxdepth: 2
:titlesonly:
:caption: DIPs
:hidden:
EOL
)

echo "$content" >> "$dir"/README.md

for filename in "$dir"/*.md; do
if [ $(basename "$filename") = "README.md" ]
then
echo "Skipping README.md"
continue
fi

echo "Processing $filename..."

# Extract DIP number
full_dip_num=$(grep '^\s*DIP:' "$filename" | awk -F: '{print $2}' | sed 's/^ *//' | tr -d '\r')
dip="${full_dip_num#"${full_dip_num%%[!0]*}"}"

# Extract title
title=$(grep '^\s*Title:' "$filename" | awk -F: '{print $2}' | sed 's/^ *//' | tr -d '\r')

# Combine to make heading
heading="# $dip - $title"
echo "Heading $heading..."

# Create temp file
tempfile=$(mktemp)

# Write heading to temp file
echo -e "$heading\n" > "$tempfile"

# Append original file contents to temp file
cat "$filename" >> "$tempfile"

# Move temp file to original file
mv "$tempfile" "$filename"

# Write the filename to the toctree
echo "dip-$full_dip_num" >> "$dir"/README.md
done

# Close out the toctree
closing_content=$(cat <<EOL
\`\`\`
EOL
)

echo "$closing_content" >> "$dir"/README.md

# Output the updated readme
cat "$dir"/README.md

echo "Finished processing files."

0 comments on commit 648e064

Please sign in to comment.