Compare commits

...

17 Commits

Author SHA1 Message Date
Jake Howard d9db94273d Hide some pages from search 2024-02-17 22:52:16 +00:00
Jake Howard b8855c0f90 Set fetch depth to remove warning about date 2024-02-17 22:46:23 +00:00
Jake Howard ca52fa6bf5 Add note about tag navigation 2024-02-17 22:43:19 +00:00
Jake Howard 5ec923590a Use tags as navigation
It looks odd when there's multiple open, but that's ok
2024-02-16 17:12:00 +00:00
Jake Howard c988131d09 Add notes list and optimise getting notes 2024-02-16 16:13:07 +00:00
Jake Howard 3108f3a01f Add content to static pages 2024-02-15 21:04:49 +00:00
Jake Howard 9fc4cd919f Add justfile 2024-02-15 20:46:46 +00:00
Jake Howard 1faeb1dfe5 Add plausible 2024-02-15 20:42:42 +00:00
Jake Howard 2cb19bf2a1 Add "back to top" button 2024-02-15 19:54:44 +00:00
Jake Howard d79f3a5e3c Improve page order 2024-02-15 19:52:07 +00:00
Jake Howard 1b4672d615 Add RSS feed 2024-02-15 19:51:36 +00:00
Jake Howard f6d1741c0d Add social cards 2024-02-15 19:13:59 +00:00
Jake Howard 15a3ef9fbc Minify output 2024-02-15 19:06:37 +00:00
Jake Howard 04389256db Add social links 2024-02-15 18:24:26 +00:00
Jake Howard 6ad4c74b54 Add copyright 2024-02-15 18:11:17 +00:00
Jake Howard 234e7046c0 List recent notes on homepage 2024-02-15 18:07:13 +00:00
Jake Howard 93a375b482 Use mkdocs-mateiral 2024-02-13 23:16:21 +00:00
31 changed files with 535 additions and 47 deletions

View File

@ -1,6 +1,13 @@
name: CI
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
# Allow running manually
workflow_dispatch:
permissions:
contents: read
@ -11,23 +18,39 @@ concurrency:
group: "pages"
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Hugo
uses: crazy-max/ghaction-hugo@v2
with:
version: latest
extended: true
args: --minify --verbose
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- uses: taiki-e/install-action@just
- run: just setup
- name: Setup Pages
uses: actions/configure-pages@v1
- name: Build
run: just build
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./public
path: ./site
deploy:
environment:

187
.gitignore vendored
View File

@ -1,21 +1,176 @@
# Created by https://www.toptal.com/developers/gitignore/api/hugo
# Edit at https://www.toptal.com/developers/gitignore?templates=hugo
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python
### Hugo ###
# Generated files by hugo
/public/
/resources/_gen/
/assets/jsconfig.json
hugo_stats.json
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# Executable may be added to repository
hugo.exe
hugo.darwin
hugo.linux
# C extensions
*.so
# Temporary lock file while building
/.hugo_build.lock
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# End of https://www.toptal.com/developers/gitignore/api/hugo
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
/resources
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml
# ruff
.ruff_cache/
# LSP config files
pyrightconfig.json
# End of https://www.toptal.com/developers/gitignore/api/python

View File

@ -1,9 +0,0 @@
baseURL: https://notes.theorangeone.net
title: Notes
enableGitInfo: true
cleanDestinationDir: true
module:
imports:
- path: github.com/RealOrangeOne/hugo-theme-notes

4
docs/.pages Normal file
View File

@ -0,0 +1,4 @@
nav:
- README.md
- colophon.md
- ...

15
docs/README.md Normal file
View File

@ -0,0 +1,15 @@
---
template: home.html
hide: [toc]
search:
exclude: true
---
# Notes
Things I've learned, and need to remember - so future me has a chance of using the knowledge.
!!! warning
These notes are mine, collected over time. Just because I've said it here, doesn't mean it's the absolute best practice. It worked for me, it might work for you.
If you're interested, there's an [RSS feed](/feed_rss_created.xml).

13
docs/colophon.md Normal file
View File

@ -0,0 +1,13 @@
---
hide: [toc]
search:
exclude: true
---
# Colophon
This site is built with [`mkdocs`](https://www.mkdocs.org/) and [`mkdocs-material`](https://squidfunk.github.io/mkdocs-material/). Sure, it's designed for docs, but with a few modifications (like the [`tags`](https://squidfunk.github.io/mkdocs-material/plugins/tags/) plugin) it can be used for notes. I made some fairly [large modifications](notes/mkdocs-nav-by-tag.md) to how tags work, so the sidebar is structured by tag rather than by directory (directories are fairly arbitrary, and might get removed entirely in future).
It's been through a few iterations in the past, starting with [`gatsby-theme-code-notes`](https://github.com/mrmartineau/gatsby-theme-code-notes/), on to [`hugo-theme-notes`](https://github.com/RealOrangeOne/hugo-theme-notes/), and finally here.
The code is hosted on [GitHub](https://github.com/RealOrangeOne/notes/), and deployed to [GitHub Pages](https://realorangeone.github.io/notes/).

View File

@ -19,7 +19,7 @@ FROM pg_stat_activity
WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
```
Also see [running queries](../running-queries).
Also see [running queries](./running-queries.md).
# Stopping a given connection

View File

@ -6,7 +6,7 @@ modified: 2022-09-09
This is an example note, see below for some code.
```js
```javascript
{
resolve: 'gatsby-theme-code-notes',
options: {

7
docs/notes/index.md Normal file
View File

@ -0,0 +1,7 @@
---
hide: [toc]
search:
exclude: true
---
# Notes

View File

@ -0,0 +1,16 @@
---
title: Navigate mkdocs by tag
tags:
- mkdocs
---
The sidebar for this notes site uses tags for the hierarchy, rather than by the filesystem structure.
This works by retrieving the tags for each note, creating fake sections for each, and replacing the existing sections with those.
!!! warning
Here be dragons.
```python
{! ../hooks/tag_nav.py !}
```

5
go.mod
View File

@ -1,5 +0,0 @@
module git.theorangeone.net/jake/notes
go 1.20
require github.com/RealOrangeOne/hugo-theme-notes v0.0.0-20230724125946-aaef005ab72e // indirect

2
go.sum
View File

@ -1,2 +0,0 @@
github.com/RealOrangeOne/hugo-theme-notes v0.0.0-20230724125946-aaef005ab72e h1:Bl4Ff7S7pPFkdX0pLA7YAbXDR1wqQVq7YxVA3PLIfws=
github.com/RealOrangeOne/hugo-theme-notes v0.0.0-20230724125946-aaef005ab72e/go.mod h1:ZMXpRbmG28r6mLfK/Nm93LgqjXCgUv+4ySLF3rkjSTo=

32
hooks/notes.py Normal file
View File

@ -0,0 +1,32 @@
import jinja2
from mkdocs.structure.nav import Navigation
@jinja2.pass_context
def get_page(context, slug):
nav = context["nav"]
for page in nav.pages:
if page.file.src_uri == slug:
return page
raise ValueError("Unable to find page for '%s'", slug)
def get_notes_from_nav(nav: Navigation):
notes_section = next(item for item in nav if item.is_section and item.title == "Notes")
notes = [item for item in nav.pages if item.is_page and notes_section in item.ancestors and item.file.src_uri != "notes/index.md"]
return notes_section, notes
@jinja2.pass_context
def get_notes(context):
notes_section, notes = get_notes_from_nav(context["nav"])
return sorted(notes, key=lambda p: p.meta["git_creation_date_localized_raw_iso_date"], reverse=True)
def on_env(env, config, files):
env.tests["startswith"] = str.startswith
env.globals["get_page"] = get_page
env.globals["get_notes"] = get_notes

55
hooks/tag_nav.py Normal file
View File

@ -0,0 +1,55 @@
import sys
import os
sys.path.insert(0, os.path.dirname(__file__))
from notes import get_notes_from_nav
from mkdocs.structure.nav import Navigation, Section
from collections import defaultdict
from mkdocs.utils import meta
from mkdocs.plugins import event_priority
class TagSection(Section):
"""
A modified section which is active if any of its children are active
(regardless of what mkdocs tells it).
"""
@property
def active(self):
return any(c.active for c in self.children)
@active.setter
def active(self, value: bool):
pass
@event_priority(100)
def on_nav(nav: Navigation, config, files):
"""
Structure the nav sections by tag
"""
notes_section, notes = get_notes_from_nav(nav)
notes_page = notes_section.children[0]
pages_to_tag = defaultdict(list)
orphan_pages = []
for note in notes:
with open(note.file.abs_src_path) as f:
_, metadata = meta.get_data(f.read())
if tags := metadata.get("tags"):
for tag in tags:
pages_to_tag[tag].append(note)
else:
orphan_pages.append(note)
tag_sections = [
TagSection(tag, pages)
for tag, pages in pages_to_tag.items()
]
notes_section.children = tag_sections + orphan_pages + [notes_page]

View File

@ -1,9 +1,15 @@
export PATH := "./env/bin:" + env_var('PATH')
# Recipes
@default:
just --list
just --list
start:
hugo server
setup:
python -m venv env
env/bin/pip install -r requirements.txt
build:
hugo
@start:
mkdocs serve
@build:
mkdocs build -v

114
mkdocs.yml Normal file
View File

@ -0,0 +1,114 @@
site_name: Notes
site_url: https://notes.theorangeone.net
repo_url: https://github.com/RealOrangeOne/notes
repo_name: RealOrangeOne/notes
copyright: "© TheOrangeOne"
extra:
social:
- icon: fontawesome/solid/globe
link: https://theorangeone.net
- icon: fontawesome/brands/mastodon
link: https://theorangeone.net/@jake
- icon: fontawesome/brands/twitter
link: https://twitter.com/RealOrangeOne
- icon: fontawesome/brands/github
link: https://github.com/RealOrangeOne
- icon: fontawesome/solid/rss
link: /feed_rss_created.xml
analytics:
provider: plausible
domain: notes.theorangeone.net
src: https://elbisualp.theorangeone.net/js/script.js
theme:
name: material
features:
- navigation.top
- navigation.sections
- navigation.indexes
- toc.follow
- search.suggest
- navigation.top
icon:
logo: fontawesome/regular/note-sticky
favicon: https://theorangeone.net/favicon.ico
custom_dir: theme/
palette:
# Palette toggle for light mode
- scheme: default
primary: deep orange
accent: orange
toggle:
icon: material/brightness-7
name: Switch to dark mode
# Palette toggle for dark mode
- scheme: slate
primary: deep orange
accent: orange
toggle:
icon: material/brightness-4
name: Switch to light mode
hooks:
- hooks/notes.py
- hooks/tag_nav.py
# Extensions
markdown_extensions:
- attr_list
- abbr
- pymdownx.highlight
- pymdownx.superfences
- footnotes
- markdown.extensions.admonition
- markdown.extensions.def_list
- markdown.extensions.toc:
permalink: true
- pymdownx.betterem:
smart_enable: all
- pymdownx.caret
- pymdownx.details
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
- pymdownx.inlinehilite
- pymdownx.keys
- pymdownx.magiclink
- pymdownx.mark
- pymdownx.progressbar
- pymdownx.smartsymbols
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.tilde
- mdx_include:
base_path: docs
plugins:
- search
- glightbox
- awesome-pages:
strict: true
order: asc
sort_type: natural
order_by: title
- tags:
enabled: true
tags_file: notes/index.md
- git-revision-date-localized:
enable_creation_date: true
fallback_to_build_date: true
exclude:
- README.md
- notes/index.md
- minify_html
- social
- rss:
date_from_meta:
as_creation: "date"
as_update: false
json_feed_enabled: false
match_path: "notes/.*"
- material-plausible

9
requirements.txt Normal file
View File

@ -0,0 +1,9 @@
mkdocs
mkdocs-material[imaging]
mdx-include
mkdocs-awesome-pages-plugin
mkdocs-glightbox
mkdocs-git-revision-date-localized-plugin
mkdocs-minify-html-plugin
mkdocs-rss-plugin
material-plausible-plugin

23
theme/home.html Normal file
View File

@ -0,0 +1,23 @@
{% extends "base.html" %}
{% block content %}
{{ super() }}
<h2>Recent notes</h2>
{% set notes_index = get_page('notes/index.md') %}
{% set notes = get_notes() %}
<ul>
{% for page in notes[:10] %}
<li>
<a href="{{ page.url }}">{{ page.title }}</a> - {{ page.meta.git_creation_date_localized_raw_iso_date }}
{% for tag in page.meta.tags %}
<span class="md-tag">{{ tag }}</span>
{% endfor %}
</li>
{% endfor %}
</ul>
<p><a href="{{ notes_index.url }}">View all {{ notes|length }} &rarr;</a></p>
{% endblock %}

32
theme/main.html Normal file
View File

@ -0,0 +1,32 @@
{% extends "base.html" %}
{% block announce %}
You can also find me at
<a href="https://theorangeone.net/">
<span class="twemoji globe">
{% include ".icons/fontawesome/solid/globe.svg" %}
</span>
<strong>My website</strong>
</a>,
or on social media:
<a rel="me" href="https://theorangeone.net/@jake">
<span class="twemoji globe">
{% include ".icons/fontawesome/brands/mastodon.svg" %}
</span>
<strong>Mastodon</strong>
</a>
,
<a href="https://twitter.com/RealOrangeOne">
<span class="twemoji twitter">
{% include ".icons/fontawesome/brands/twitter.svg" %}
</span>
<strong>Twitter</strong>
</a>
,
<a href="https://github.com/RealOrangeOne">
<span class="twemoji github">
{% include ".icons/fontawesome/brands/github.svg" %}
</span>
<strong>GitHub</strong>
</a>.
{% endblock %}