diff --git a/.github/workflows/docs-action.yml b/.github/workflows/docs-action.yml index fd5011f60..6568b137e 100644 --- a/.github/workflows/docs-action.yml +++ b/.github/workflows/docs-action.yml @@ -5,6 +5,7 @@ on: branches: - main paths: + - ".github/workflows/docs-action.yml" - "docs/**.md" - "docs/mkdocs.yml" - "examples/python/**" @@ -114,6 +115,7 @@ jobs: DOCSBRANCH: "gh-pages" DOCSREMOTE: "origin" GITHUB_TOKEN: "${{ secrets.GH_PAGES_PAT }}" + DOCS_COMMIT_SHA: ${{ github.sha }} run: | mkdir -p ${GITHUB_WORKSPACE}/site/ cd docs diff --git a/docs/README.md b/docs/README.md index d1801a276..3925aa501 100644 --- a/docs/README.md +++ b/docs/README.md @@ -20,5 +20,5 @@ cd docs; uv run mkdocs build To serve the docs locally ``` -cd docs; uv run mkdocs serve +cd docs; uv run mkdocs serve --verbose --livereload ``` diff --git a/docs/assets/logo.png b/docs/assets/logo.png deleted file mode 100644 index 84759d575..000000000 Binary files a/docs/assets/logo.png and /dev/null differ diff --git a/docs/hooks/git-info.py b/docs/hooks/git-info.py new file mode 100644 index 000000000..7572bd390 --- /dev/null +++ b/docs/hooks/git-info.py @@ -0,0 +1,40 @@ +import subprocess +import os + +def on_config(config): + """ + Hook to add git commit information. This runs once when MkDocs loads the config. + """ + try: + repo_root = os.path.dirname(os.path.abspath(config.config_file_path)) + commit_hash = os.environ.get('DOCS_COMMIT_SHA') + + if commit_hash: + print(f"Using commit from DOCS_COMMIT_SHA env: {commit_hash[:7]}") + short_hash = commit_hash[:7] + commit_date = subprocess.check_output( + ['git', 'log', '-1', '--format=%cd', '--date=short', commit_hash], + cwd=repo_root, + stderr=subprocess.STDOUT + ).decode('utf-8').strip() + print(f"Git hook: Loaded commit info {short_hash} • {commit_date}") + else: + # No commit details in not provided via env + print("DOCS_COMMIT_SHA not set") + + # Add to extra context (available in templates if needed) + if 'extra' not in config: + config['extra'] = {} + + config['extra']['git'] = { + 'commit': commit_hash, + 'short_commit': short_hash, + 'date': commit_date, + } + + except subprocess.CalledProcessError as e: + print(f"Warning: Could not get git information: {e}") + except Exception as e: + print(f"Warning: Error in git hook: {e}") + + return config diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index e2440d2e6..c4e1fe1d8 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -4,13 +4,10 @@ docs_dir: src repo_url: https://github.com/Blockstream/greenlight edit_uri: tree/main/docs/src -plugins: - - search - - social - - redirects: - redirect_maps: - 'reference/partner-certs.md': 'getting-started/certs.md' - +hooks: + - hooks/git-info.py +extra_css: + - assets/stylesheets/git-info.css markdown_extensions: - admonition - attr_list @@ -33,6 +30,7 @@ markdown_extensions: base_path: ["../examples/rust/snippets", "../examples/python/snippets"] theme: name: material + custom_dir: overrides logo: assets/logo.png favicon: assets/logo.png palette: @@ -53,14 +51,13 @@ theme: toggle: icon: material/weather-sunny name: Switch to light mode - features: - navigation.tabs - - content.code.annotate - navigation.instant - navigation.tabs.sticky - navigation.sections - navigation.indexes + - content.code.annotate - content.tabs.link - content.code.copy @@ -93,3 +90,7 @@ nav: - About: about/index.md - Frequently Asked Questions: about/faq.md - Changelog: about/changelog.md +extra: + generator: false +copyright: | + © 2024 Greenlight All rights reserved. \ No newline at end of file diff --git a/docs/overrides/partials/header.html b/docs/overrides/partials/header.html new file mode 100644 index 000000000..3abbb742d --- /dev/null +++ b/docs/overrides/partials/header.html @@ -0,0 +1,85 @@ +{%- set class = "md-header" -%} +{%- if "navigation.tabs.sticky" in features -%} + {%- set class = class ~ " md-header--shadow md-header--lifted" -%} +{%- elif "navigation.tabs" not in features -%} + {%- set class = class ~ " md-header--shadow" -%} +{%- endif -%} +
+ + {% if "navigation.tabs.sticky" in features %} + {% if "navigation.tabs" in features %} + {% include "partials/tabs.html" %} + {% endif %} + {% endif %} +
+{% if "navigation.tabs" in features %} + {% if "navigation.tabs.sticky" not in features %} + {% include "partials/tabs.html" %} + {% endif %} +{% endif %} \ No newline at end of file diff --git a/docs/src/assets/stylesheets/git-info.css b/docs/src/assets/stylesheets/git-info.css new file mode 100644 index 000000000..9642e085c --- /dev/null +++ b/docs/src/assets/stylesheets/git-info.css @@ -0,0 +1,34 @@ +.git-info-bar { + font-size: 0.5rem; +} + +.git-info-bar .md-grid { + display: flex; + justify-content: center; + align-items: center; + opacity: .75; +} + +.git-info-item { + display: flex; + align-items: center; + gap: 0.2rem; + padding-right: 0.3rem; +} + +.git-info-item:last-child { + padding-right: 1rem; +} + +.git-info-item svg { + width: 0.5rem; + height: 0.5rem; +} + +.git-info-item a { + text-decoration: none; +} + +.git-info-item a:hover { + text-decoration: none; +}