Fix code blocks

This commit is contained in:
Gabriel Augendre 2023-05-21 11:02:39 +02:00
parent a3265a50db
commit 28483f870d
9 changed files with 25 additions and 24 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
.hugo_build.lock
.idea
public/

View file

@ -45,7 +45,7 @@ params:
tocopen: false
assets:
# disableHLJS: true # to disable highlight.js
disableHLJS: true
# disableFingerprinting: true
favicon: "<link / abs url>"
favicon16x16: "<link / abs url>"
@ -111,15 +111,15 @@ menu:
url: /search/
weight: 30
# Read: https://github.com/adityatelange/hugo-PaperMod/wiki/FAQs#using-hugos-syntax-highlighter-chroma
pygmentsUseClasses: true
#pygmentsUseClasses: true
markup:
highlight:
noClasses: false
# anchorLineNos: true
# codeFences: true
# guessSyntax: true
# lineNos: true
# style: monokai
# noClasses: true
codeFences: true
guessSyntax: true
# lineNos: true
# anchorLineNos: true
style: catppuccin-macchiato
outputs:
home:

View file

@ -9,7 +9,7 @@ Today I learned that recursively changing the owner of a directory tree in a Doc
## 🚛 The issue
You may remember how in a [previous post]({{< ref "docker-images-layers-and-cache/" >}}) we used a small example to discuss layers and final image size. Well, here's our example again, slightly modified.
```Dockerfile hl_lines="5"
```Dockerfile {hl_lines="5"}
# Dockerfile
FROM ubuntu
WORKDIR /app
@ -40,7 +40,7 @@ RUN chown -R 33:33 /app
This results in an image weighing 492MB. Let's bring it down to 283MB! (2x~100MB + ~75MB)
```Dockerfile hl_lines="9 14 15 19"
```Dockerfile {hl_lines="9 14 15 19"}
FROM ubuntu AS build
WORKDIR /build
RUN fallocate -l 100M binary

View file

@ -48,7 +48,7 @@ This is a warning admonition.
This is a danger admonition.
{{< /note >}}
```python hl_lines="1 3"
```python {hl_lines="1 3"}
# main.py
def main():

View file

@ -88,7 +88,7 @@ We'll add another stage to this build. First, we will install poetry and the pro
### Multi-staged dependencies & code
```Dockerfile hl_lines="15 22 24"
```Dockerfile {hl_lines="15 22 24"}
# Dockerfile
## Build venv
FROM python:3.8.6-buster AS venv
@ -136,7 +136,7 @@ Your ops teams should be happier with these lighter images: less attack surface,
For this blog, I use a slightly modified version of what we just saw:
```Dockerfile hl_lines="15 17 21 27 33 34 40 41 42 44 45 46"
```Dockerfile {hl_lines="15 17 21 27 33 34 40-42 44-46"}
# Dockerfile
## Build venv
FROM python:3.8.6-buster AS venv

View file

@ -10,7 +10,7 @@ Today, while working on a project at [ITSF](https://itsf.io), I needed to add a
## 🧒🏻 First try
So I sat down, thought about it, and here's the migration I first came up with:
```{ .python .large }
```python
def forwards(apps, schema_editor):
Model = apps.get_model('app', 'Model')
db_alias = schema_editor.connection.alias
@ -40,7 +40,7 @@ Fortunately, Django comes with batteries included and provides a pagination mech
After re-engineering, here's the updated version which will obviously make many more DB queries but will hopefully not send our RAM to a black hole 😁
```{ .python .large hl_lines="5 6 7" }
```python {hl_lines="5-7"}
def forwards(apps, schema_editor):
Model = apps.get_model('app', 'Model')
db_alias = schema_editor.connection.alias

View file

@ -69,7 +69,7 @@ pytest>=7.0
The commands used to compile the three files are:
```{ .shell .large }
```shell
pip-compile -q --allow-unsafe --resolver=backtracking --generate-hashes requirements.in
pip-compile -q --allow-unsafe --resolver=backtracking --strip-extras -o constraints.txt requirements.in
pip-compile -q --allow-unsafe --resolver=backtracking --generate-hashes requirements-dev.in
@ -77,7 +77,7 @@ pip-compile -q --allow-unsafe --resolver=backtracking --generate-hashes requirem
This is a lot to remember and I have a terrible memory, so I'm using [invoke](https://www.pyinvoke.org/) to call the commands for me.
```{ .python .large }
```python
# tasks.py
from pathlib import Path
@ -158,7 +158,7 @@ git commit -m "Add new_package"
In order to avoid forgetting to compile my dependencies, I added a few pre-commit hooks to my projects:
```{ .yaml .large }
```yaml
repos:
- repo: https://github.com/jazzband/pip-tools
rev: 6.12.2

View file

@ -29,14 +29,14 @@ SSH is perfect for this. It allows you to remotely connect to any computer you'r
A good thing to do when enabling SSH on your machine is to change the port it listens to. By default, SSH expects you to connect on port 22. The bad guys know this, and might try to force into your machine if you leave it unprotected and accessible from the internet listening on port 22. To change the SSH port on Debian, you'll have to edit a file and restart `sshd`:
```{ .bash .large }
```shell
sed -i ".bak" "s/Port 22/Port 23574/" /etc/ssh/sshd_config
systemctl restart service sshd
```
I also usually install `ufw` and restrict the ports I open on the machine. This prevents unexpected programs to receive connections unless I authorize them.
```{ .bash .large }
```shell
# Let's not prevent ourselves from logging in before enabling the rules.
ufw allow 23574
ufw enable
@ -60,7 +60,7 @@ At last, the need to have some backup strategy arises when you start to run more
As promised in [the article about my Synology NAS and the backups]({{< ref "synology-nas-stream-and-backup" >}}), here is the script I use to regularly backup my Raspberry Pi important files. This is the Home Assistant version, the other script is nearly identical except for the files included in the zip archive.
```{ .bash .large }
```shell
#!/bin/bash
set -e
@ -100,7 +100,7 @@ This script:
For this simple script to work, I had to mount a volume of my NAS on the Raspberry Pi. This is done by adding a new line to the [`/etc/fstab`](https://en.wikipedia.org/wiki/Fstab) file:
```{ .text .large }
```text
//<ip_address>/backup /mnt/synology-backup cifs username=<username>,password=<password> 0 0
```
@ -108,7 +108,7 @@ This mounts the `/backup` volume of my NAS to the `/mnt/synology-backup` folder
And the last piece of the puzzle: to run the script periodically I had to edit a [`crontab`](https://en.wikipedia.org/wiki/Cron). `cron` is a Linux program designed to run periodical tasks. It's based on a file called a `crontab` which tells what to run when. Each user has its own `crontab`. I decided to use root's to run my scripts so that I won't run into permission issues:
```{ .text .large }
```text
30 3 * * * /home/homeassistant/backup.sh >> /home/homeassistant/backup.log
```

View file

@ -80,7 +80,7 @@ Here's what the template looked like:
## Implementation
Here's how the template looks like with htmx. I've removed the non-relevant parts for brevity.
```jinja hl_lines="2 8 12 17 18 19 20"
```jinja {hl_lines="2 8 12 17-20"}
{% extends "common/base.html" %}
{% load static i18n purchase django_htmx %}
{# ... #}