Compare commits

...

8 Commits

32 changed files with 337 additions and 58 deletions

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "v2/themes/cupper-hugo-theme"] [submodule "v2/themes/cupper-hugo-theme"]
path = v2/themes/cupper-hugo-theme path = v2/themes/cupper-hugo-theme
url = https://github.com/zwbetz-gh/cupper-hugo-theme.git url = gitea@home.hugopoi.net:hugopoi/cupper-hugo-theme.git

14
deploy.sh Normal file → Executable file
View File

@ -1,9 +1,15 @@
#!/bin/bash #!/bin/bash
# Build # Build
cd v2
hugo hugo
cd ..
# Backup current deploy # Backup current deploy
ssh home.hugopoi.net sudo yunohost backup create --apps my_webapp ssh home.hugopoi.net sudo yunohost backup create --apps my_webapp
# Deploy full legacy and new blog echo "$1"
rsync -rlgoD --checksum --verbose www/ home.hugopoi.net:/var/www/my_webapp/www/ if [[ "$1" == "--full" ]]; then
# Deploy only the new hugo blog echo "Deploy full legacy and new blog"
rsync -rlgoD --verbose --checksum --delete www/v2/ home.hugopoi.net:/var/www/my_webapp/www/v2/ rsync -rlgoD --checksum --verbose www/ home.hugopoi.net:/var/www/my_webapp/www/
else
echo "Deploy only the new hugo blog"
rsync -rlgoD --verbose --checksum --delete www/v2/ home.hugopoi.net:/var/www/my_webapp/www/v2/
fi

View File

@ -4,7 +4,7 @@ server {
# error_log /var/log/nginx/error.log; # error_log /var/log/nginx/error.log;
# access_log /var/log/nginx/access.log; # access_log /var/log/nginx/access.log;
root /var/www/html; root /var/www/html;
try_files $uri $uri/ /index.php /index.html; try_files $uri $uri/ /index.php;
location ~ \.php$ { location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000; fastcgi_pass php-fpm:9000;

View File

@ -30,10 +30,10 @@ search = true
showThemeSwitcher = true showThemeSwitcher = true
defaultDarkTheme = false defaultDarkTheme = false
moveFooterToHeader = true moveFooterToHeader = true
logoAlt = "An alternative text description of the logo" logoAlt = "HugoPoi's blog v2"
# customCss = [ "css/custom_01.css", "css/custom_02.css" ] customCss = [ "css/cupper-hugo-tweaks.css" ]
# customJs = [ "js/custom_01.js", "js/custom_02.js" ] # customJs = [ "js/custom_01.js", "js/custom_02.js" ]
navTitleText = "HugoPoi's blog v2" # navTitleText = "HugoPoi's blog v2"
[[menu.nav]] [[menu.nav]]
@ -41,16 +41,16 @@ name = "Home"
url = "/" url = "/"
weight = 1 weight = 1
# [[menu.nav]] [[menu.nav]]
# name = "Blog" name = "Blog"
# url = "/post/" url = "/post/"
# weight = 2 weight = 2
# [[menu.nav]] [[menu.nav]]
# name = "Tags" name = "How this blog is made"
# url = "/tags/" url = "/how-this-blog-is-made/"
# weight = 3 weight = 3
#
# [[menu.nav]] # [[menu.nav]]
# name = "About" # name = "About"
# url = "/about/" # url = "/about/"

Binary file not shown.

After

Width:  |  Height:  |  Size: 817 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View File

@ -0,0 +1,184 @@
---
title: "How this blog is made, Archivarix, some PHP and Hugo"
date: 2022-11-06T15:07:16+01:00
draft: true
toc: true
tags: ["youpi"]
---
## The legacy of my blog, recover with Archivarix
For me this year was like a rollercoaster, and I forget my blog was
hosted on a very old Online.net Dedibox server, now called Scaleway.
This server was in a process to be decomission and I missed the 3 emails
annoncing the end of my services. Then Online.net decided that it was a
good idea to also delete the backups spaces attached to these machines.
To sumup I loose my blog and the recent backups. But I wanted to keep it
and a least serve the existing content that was linked on search
engines and other websites. I looked on the wayback machine and my blog
was in it. I found a cool all-in-one service to restore an entire
website from the Wayback machine called Archivarix, the cost was arround
10€.
I recovered a 300MB zip archive with a lot of content, some
images are missing but all the articles was there.
## Running the Archivarix Loader
Archivarix loader is a single php file using a sqlite database with all
your urls inside and the content is stored as files in `www/.content.EZtzwPjb/binary/`.
Each time a HTTP request is process, the script look in the database for
a matching url and serve the content linked to it. This mini cms is
license under GPL, and I put a copy [here](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/src/branch/master/www/index.php).
### With docker
You need PHP and SQLite extension, the PHP docker image already
contains that. I have done a small docker-compose for running
archivarix.
Simple as run `docker compose up`.
* [docker-compose.yml](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/src/branch/master/docker-compose.yml)
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/branch/master/docker-compose.yml" data-range="1," class="line-numbers"></pre>
* [nginx.conf](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/src/branch/master/nginx.conf)
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/branch/master/nginx.conf" data-range="1," class="line-numbers language-nginx"></pre>
{{< figureCupper
img="Screenshot 2022-11-20 at 18-54-58 HugoPoi Internet Hardware et Bidouille.png"
caption="First run of my old website"
command="Fill"
options="1024x500 Top" >}}
### With Yunohost
I'm mainly self-hosted with the Yunohost project, those next steps show
you how to easily add a small php inside your Yunohost instance.
1. Install the application `My Webapp` inside the yunohost admin panel
{{< figureCupper
img="Screenshot from 2022-11-21 18-40-13.png"
caption="TODO"
command="Fit"
options="1024x500" >}}
1. Fill the setup form
{{< figureCupper
img="Screenshot 2022-11-21 at 18-41-13 Install my_webapp _ Catalog YunoHost Admin.png"
caption="TODO"
command="Fill"
options="1024x500" >}}
1. You have an empty app inside `/var/www/my_webapp/www/`
{{< figureCupper
img="Screenshot from 2022-11-21 18-42-30.png"
caption="TODO"
command="Fit"
options="1024x500" >}}
1. You need to copy your files, I use rsync with the yunohost admin account
`rsync -rlgoD --checksum --verbose www/ admin@home.hugopoi.net:/var/www/my_webapp/www/`
1. Then you might need to `chmod 664 /var/www/my_webapp/www/.content.*/structure.*`, Archivarix required some write access on the sqlite files.
## Modding Archivarix Loader
### Fixing Wordpress version missing files
The homepage was looking good but some wordpress css and javascript assets were missing. Wordpress use a query params `?ver=`.
{{< figureCupper
img="Screenshot 2022-11-20 at 18-55-57 Linky opendata my ass HugoPoi.png"
caption="First run of my old website, some broken css looking wrong"
command="Fill"
options="1024x500 Top" >}}
{{< figureCupper
img="Screenshot-Firefix-debugger-404-ver-wordpress-archivarix.png"
caption="Missing files because of the Wordpress `?ver=` query params with Archivarix"
command="Fit"
options="1024x500" >}}
So I code a little function to load any version available for a
given url. And I take the most recent one.
* [`getOtherWordpressVersionUrls` function in www/index.php](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/src/commit/2a154a6eea510e08b2608fd55f6729056c363b25/www/index.php#L295-L305)
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/commit/2a154a6eea510e08b2608fd55f6729056c363b25/www/index.php" data-range="295,305" class="line-numbers"></pre>
* [The call in www/index.php](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/src/commit/2a154a6eea510e08b2608fd55f6729056c363b25/www/index.php#L609-L614)
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/commit/2a154a6eea510e08b2608fd55f6729056c363b25/www/index.php" data-range="608,620" class="line-numbers"></pre>
### Cleaning existing pages
After successfully running my backuped blog, I wanted to mod some
content.
* Replace the twitter widget
* Replace the hoster widget
* Add a legacy warning for visitor to redirect to the new blog
Archivarix has a `ARCHIVARIX_INCLUDE_CUSTOM` relying
on regular expression to replace content but I needed a more precise approach. I used the PHP XML extension which has a DOM parser buit in and can
parse HTML pages.
* [The easy config to add/replace/delete some html parts](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/src/commit/cd94d82c1a3dad22b026c9c26311b366f76dcd54/www/index.php#L97-L133)
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/commit/cd94d82c1a3dad22b026c9c26311b366f76dcd54/www/index.php" data-range="115,134" class="line-numbers"></pre>
* [The clever mod](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/commit/598d28551d071774007172782541e1d140b8a3c1#diff-eb630ac88267e24589fd94de0826721dff38beb4)
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/commit/598d28551d071774007172782541e1d140b8a3c1/www/index.php" data-range="411,439" class="line-numbers"></pre>
## The new blog with Hugo
I wanted simple markdown that generate static HTML, this why I choose Hugo for my blog.
1. First I add a new directory called `v2` next to the legacy blog.
1. Then you launch `hugo new site v2` this will generate the folder tree needed.
1. I choose the Cupper theme
{{< figureCupper
img="Screenshot 2022-12-03 at 15-30-20 Cupper.png"
caption="Cupper Theme for Hugo"
command="Fit"
options="1024x500" >}}
1. I add the Cupper theme with `git submodule add https://github.com/zwbetz-gh/cupper-hugo-theme.git themes/cupper-hugo-theme`
1. Add some [custom css](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/src/commit/80eed4ba721287f4854f26e62a094b26997b4b69/v2/static/css/cupper-hugo-tweaks.css)
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/commit/80eed4ba721287f4854f26e62a094b26997b4b69/v2/static/css/cupper-hugo-tweaks.css" class="line-numbers"></pre>
1. Add some config in [`config.toml`](https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/src/branch/master/v2/config.toml)
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/commit/80eed4ba721287f4854f26e62a094b26997b4b69/v2/config.toml" class="line-numbers"></pre>
1. I also upgrade prism.js for code highlight in theme itself
1. I add favicon and logo
1. Then I need to build with `hugo`
1. Deploy with rsync in yunohost
<pre data-src="https://home.hugopoi.net/gitea/hugopoi/blog.hugopoi.net/raw/branch/master/deploy.sh" class="line-numbers"></pre>
1. I add a CORS header in nginx config
of my Gitea to allow fetching code inside `<pre>` html tags
```nginx
rewrite ^/gitea$ /gitea/ permanent;
location /gitea/ {
proxy_pass http://localhost:6000/;
proxy_set_header Host $host;
proxy_buffering off;
client_max_body_size 200M;
proxy_set_header X-Real-IP $remote_addr;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
add_header 'Vary' 'Origin';
# Add CORS header for loading code in pre html tags
if ($http_origin ~* "^(http://localhost:1313|https://blog.hugopoi.net)$") {
add_header Access-Control-Allow-Origin "$http_origin";
}
}
```
Moooore to come !

View File

@ -1,38 +0,0 @@
---
title: "How this blog is made, Archivarix, some PHP and Hugo"
date: 2022-11-06T15:07:16+01:00
draft: true
---
Omg first post !
## The legacy of my blog, recover with Archivarix
For me this year was like rollercoaster, and I forget that my blog was
hosted on a very old Online.net Dedibox server, now called Scaleway.
This server was in a process to be decomission and I missed the 3 emails
annoncing the end of my services. Then Online.net decided that it was a
good idea to also delete the backups spaces attached to these machines.
To sumup I loose my blog and the recent backups. But I wanted to keep it
and a least serve the existing content that was linked on search
engines and other websites. I looked on the wayback machine and my blog
was in it. I found a cool all-in-one service to restore an entire
website from the Wayback machine called Archivarix, the cost was arround
10€.
I recovered a 300MB zip archive with a lot of content, some
images are missing but all the articles are there I think. I test it
## Running the Archivarix Loader
### With docker
### With Yunohost
## Fixing some missing files
## Modding Archivarix Loader
## The new blog with Hugo
Go Hugo !

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#2b5797</TileColor>
</tile>
</msapplication>
</browserconfig>

View File

@ -0,0 +1,12 @@
body {
font-size: calc(1em + 0.20vw);
}
.main-and-footer > div {
max-width: initial;
}
.pattern [aria-current] {
clip-path: none;
border-radius: 0.33em;
}

BIN
v2/static/favicon-16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

BIN
v2/static/favicon-32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 926 B

BIN
v2/static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

74
v2/static/images/logo.svg Normal file
View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="30mm"
height="30mm"
viewBox="0 0 30 30"
version="1.1"
id="svg894"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
sodipodi:docname="logo hugopoi v1.2.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<defs
id="defs888" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="4.0983237"
inkscape:cx="94.306851"
inkscape:cy="61.732557"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
inkscape:document-rotation="0"
showgrid="false"
inkscape:window-width="1920"
inkscape:window-height="995"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:pagecheckerboard="0" />
<metadata
id="metadata891">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:#1199a6;fill-opacity:1;stroke:none;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 29.949306,10.531903 v 16.825 h -12 v -3 h 9 v -13.825 z"
id="path1465"
sodipodi:nodetypes="ccccccc" />
<g
aria-label="HP"
transform="matrix(0.76409264,0,0,1.3087418,-4.9451562e-4,-2.6302276)"
id="text898"
style="font-size:31.444px;line-height:1.25;letter-spacing:-5.78644px;word-spacing:0px;stroke-width:0.277317">
<path
d="M 3.7550926e-6,4.0438278 H 5.9111073 V 11.238816 H 14.631904 V 4.0438278 h 5.911104 V 22.922768 H 14.631904 V 14.918502 H 5.9111073 v 8.004266 H 3.7550926e-6 Z"
style="fill:#646769;stroke-width:0.25167"
id="path27743" />
<path
d="m 20.529491,4.0492634 h 9.810897 q 4.375752,0 6.709486,1.6054487 2.349088,1.5928075 2.349088,4.5508789 0,2.970712 -2.349088,4.57616 -2.333734,1.592808 -6.709486,1.592808 h -3.899793 v 6.548209 h -5.911104 z m 5.911104,3.5269308 v 5.2714348 h 3.270299 q 1.719594,0 2.656158,-0.682632 0.936564,-0.695273 0.936564,-1.959406 0,-1.2641333 -0.936564,-1.946765 -0.936564,-0.6826318 -2.656158,-0.6826318 z"
style="fill:#e0892b;stroke-width:0.251634"
id="path27745" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
v2/static/mstile-70x70.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,19 @@
{
"name": "HugoPoi's Blog",
"short_name": "HugoPoi's Blog",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}

@ -1 +1 @@
Subproject commit 4a56374eeb217c78d9fc9e3c600c899e848acf21 Subproject commit 2f7a0351f101684e7b0fdc1ec726499ae247f7a5

BIN
www/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -117,6 +117,10 @@ const ARCHIVARIX_INCLUDE_CUSTOM = array(
'OPERATION' => 'REMOVE', 'OPERATION' => 'REMOVE',
'XPATH' => '//*[@id="twitter-2"]', 'XPATH' => '//*[@id="twitter-2"]',
], ],
[
'OPERATION' => 'REMOVE',
'XPATH' => '//*[@id="twitter-widgets-js"]',
],
// replace the hoster information widget in the right column on all pages // replace the hoster information widget in the right column on all pages
[ [
@ -131,6 +135,15 @@ const ARCHIVARIX_INCLUDE_CUSTOM = array(
'XPATH' => '//nav[contains(@class, "navbar")]', 'XPATH' => '//nav[contains(@class, "navbar")]',
'FILE' => 'warning_new_blog.php', 'FILE' => 'warning_new_blog.php',
], ],
// Remove Matomo tracker
[
'FILE' => 'empty_tracker.html',
'KEYPHRASE' => '<!-- Matomo -->.*<!-- End Matomo Code -->',
'LIMIT' => 1,
'REGEX' => 1,
'POSITION' => 0,
],
); );
/** /**