Last active
April 8, 2025 13:49
-
-
Save NiceRath/e54a0c79f6b6eaa879bfa00302b1e3ce to your computer and use it in GitHub Desktop.
Sphinx - Add Create/Modify Timestamps (SEE LINK FOR GIT-REPO)
This file contains hidden or 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
#!/usr/bin/env bash | |
# FOR GIT SUPPORT: https://gist.github.com/NiceRath/0f1e20bef3d0eea993f7439bc8fc96e6 | |
# NOTE: you might need to change '/contentinfo\">' to whatever element you want to append the timestamps to | |
set -e | |
cd "$(dirname "$0")" | |
rm -rf build | |
mkdir -p build | |
sphinx-build -b html source/ build/ | |
function add_timestamps() { | |
src_file="$1" | |
file_base="$(echo "$src_file" | cut -d '/' -f 2- | sed 's|\.md||g' | sed 's|\.rst||g')" | |
dst_file="build/${file_base}.html" | |
if [[ "$src_file" == '' ]] | |
then | |
echo "FILE NOT FOUND: ${dst_file} (TIMESTAMPS)" | |
return | |
fi | |
if [[ ! -f "$src_file" ]] | |
then | |
echo "FILE NOT FOUND: ${src_file} (TIMESTAMPS)" | |
return | |
fi | |
if [[ ! -f "$dst_file" ]] | |
then | |
echo "FILE NOT FOUND: ${dst_file} (TIMESTAMPS)" | |
return | |
fi | |
create_date="$(stat -c '%w' "$src_file" | cut -d '.' -f1)" | |
update_date="$(stat -c '%y' "$src_file" | cut -d '.' -f1)" | |
sed -i "/contentinfo\">/a <p><b>Created</b>: ${create_date}</p>" "$dst_file" | |
sed -i "/contentinfo\">/a <p><b>Changed</b>: ${update_date}</p>" "$dst_file" | |
} | |
echo '### ADD CREATE/CHANGE TIMESTAMPS ###' | |
export -f add_timestamps | |
find source/ -name '*.md' -exec bash -c 'add_timestamps "$0"' {} \; | |
find source/ -name '*.rst' -exec bash -c 'add_timestamps "$0"' {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment