From bf8297543935fbcf3e608d38246e5435b3afbc77 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 23 Jun 2025 22:41:02 +0200 Subject: Improve HTML generation --- Makefile | 6 +-- build.sh | 73 +++++++++++---------------- favicon.ico | Bin 0 -> 318 bytes favicon.png | Bin 601 -> 0 bytes feed.xml | 14 ++--- genrss.sh | 5 +- index.html | 41 ++++----------- meta | 6 +++ meta.sh | 6 --- readme.md | 2 +- style.css | 27 ++++++++++ this-server/a_web_server_on_a_solar_phone.md | 3 +- this-server/index.html | 38 +++----------- this-server/meta | 7 +++ this-server/meta.sh | 6 --- 15 files changed, 100 insertions(+), 134 deletions(-) create mode 100644 favicon.ico delete mode 100644 favicon.png create mode 100644 meta delete mode 100644 meta.sh create mode 100644 style.css create mode 100644 this-server/meta delete mode 100644 this-server/meta.sh diff --git a/Makefile b/Makefile index 4041406..4814667 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,10 @@ build: ./build.sh ./genrss.sh > feed.xml -# Launch a local web server. +# Launch a local web server for validation. server: yaegi -e 'http.ListenAndServe(":8080", http.FileServer(http.Dir(".")))' -# Publish on github pages. +# Publish on my smartphone g7p publish: - git push + rsync -av --exclude=.git . g7p:www/dot.vertes.org/ diff --git a/build.sh b/build.sh index 166eeba..be30116 100755 --- a/build.sh +++ b/build.sh @@ -1,36 +1,10 @@ #!/bin/sh -header=' - - -' - md2html() { # Usage: # md2html file.md > file.html # Options: -v esc=false to not escape html -awk ' + awk ' function newblock(nblock) { if (text) print "<" block ">" text "" @@ -192,44 +166,55 @@ awk ' newblock() while (nl > 0) print "" - }' "$1" + }' "$@" } genhtml() ( cd "$1" || return - . ./meta.sh + . ./meta exec 1>index.html # Header - echo "" - echo "" - echo "" - echo "$title" - [ "$description" ] && echo "" - echo "$header" - [ "$1" != . ] && echo "$blog_title
" + cat <<- EOT + + + $title + + + + EOT # Body + [ "$1" != . ] && echo "$blog_title
" # pandoc *.md - for f in *.md; do - [ -f "$f" ] && md2html "$f" - done + md2html *.md # Footer - [ "$1" != . ] && echo "
From: $author, $date" + [ "$1" = . ] && return + echo "
From: $author, $date. Feedback" ) +urlenc() { + while [ -n "$1" ]; do + set -- "${1#?}" "${1%${1#?}}" + case $2 in + ([-._~0-9A-Za-z]) printf %c "$2" ;; + (*) printf %%%02x "'$2" ;; + esac + done + echo +} + for d in *; do [ -d "$d" ] && genhtml "$d" done genhtml . -# Fix for mastodon. -sed '/mstdn/s/href=/rel="me" href=/' index.html >xx && mv xx index.html # Put a license in index footer. -echo '
' >>index.html +' >>index.html diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..320fe47 Binary files /dev/null and b/favicon.ico differ diff --git a/favicon.png b/favicon.png deleted file mode 100644 index d7cb86d..0000000 Binary files a/favicon.png and /dev/null differ diff --git a/feed.xml b/feed.xml index f973500..41f1383 100644 --- a/feed.xml +++ b/feed.xml @@ -5,21 +5,21 @@ https://dot.vertes.org/ An experimental website on a solar phone marc@vertes.org (Marc Vertes) -Fri, 20 Jun 2025 16:58:13 +0200 +Mon, 23 Jun 2025 18:37:03 +0200 -https://dot.vertes.org/this-server/ +dot.server.org/this-server/this-server/ A web server on a solar phone -https://dot.vertes.org/this-server/ +dot.server.org/this-server/this-server/ Hosting a web server on a solar powered phone marc@vertes.org (Marc Vertes) Fri, 20 June 2025 12:00:00 +0200 A web server on a solar phone

I have this old low-cost phone which was the first one offered to my kid when he was 15 (he is now 21), before he moved to a more fashionable model. I noticed that without a SIM card, only on WIFI, the phone needed to be recharged not after 1 or 2 days, but only after 2 weeks! So this small device, plugged to a small solar panel, could be the perfect always-on personal web server. The site that you are browsing right now is hosted on it.

-

The server with its solar panel, and a cat

+

The server with its solar panel, and a cat

Hardware

-

The phone is an entry-level Motorola G7 Play, purchased in 2019 for 120€ or so, worth nothing today. It was used by my son for less than 2 years, then dormant since. The display is slighly shattered, but it doesn't matter, as I use it headless.

-

I bought a small solar panel on Amazon, 10W produced by 2 plates of 17x17 cm. Cost: 28€. I could probably get something less expensive.

+

The phone is an entry-level Motorola G7 Play, purchased in 2019, worth nothing today. It was used by my son for less than 2 years, then dormant since. The display is slighly shattered, but it doesn't matter, as I use it headless.

+

I bought a small solar panel on Amazon, 10W produced by 2 plates of 17x17 cm.

And that's it. The solar panel is just suspended vertically at a south window. The phone sits below, connected to the panel by a USB cable, in the shadow (do not put the phone directly under the sun, or closed without fresh air).

Software

The single purpose of this device is now to run a small standalone static web server. By using termux on top of Android, I can run a ssh server for remote access and Nginx, an efficient web server. I do not need to root the phone, as port redirection from my internet router compensate for the restriction of not using a port number below 1024.

@@ -30,7 +30,7 @@

Operation

It's too early to say. Lets see how it goes over time (a few months), and if a relatively old phone can find a second life and be used as an autonomous web server, running solely on free photons and electrons.

But for now, we are in june and the battery level is almost always at 100%.

-
From: Marc Vertes, 20 june 2025]]> +
From: Marc Vertes, 20 june 2025. Feedback]]>
diff --git a/genrss.sh b/genrss.sh index f92c1ac..5d2b1dc 100755 --- a/genrss.sh +++ b/genrss.sh @@ -13,7 +13,8 @@ fixhtml() { ' "$2" } -. ./meta.sh +. ./meta + cat <<- EOT @@ -28,7 +29,7 @@ EOT for d in *; do [ -d "$d" ] || continue cd $d - . ./meta.sh + . ./meta cat <<- EOT $link/$d/ diff --git a/index.html b/index.html index 7029132..56631a2 100644 --- a/index.html +++ b/index.html @@ -1,47 +1,24 @@ - - + Marc's Notes - - - - - + + +

Marc's Notes

A blog about programming and other stories.

Posts

A web server on an old smartphone, solar powered.

Contact

-
+ diff --git a/meta b/meta new file mode 100644 index 0000000..15128ac --- /dev/null +++ b/meta @@ -0,0 +1,6 @@ +title="Marc's Notes" +author="Marc Vertes" +email="marc@vertes.org" +description="An experimental website on a solar phone" +link="https://dot.vertes.org" +date="2025-06-20" diff --git a/meta.sh b/meta.sh deleted file mode 100644 index e6d75fe..0000000 --- a/meta.sh +++ /dev/null @@ -1,6 +0,0 @@ -title="Marc's Notes" -author="Marc Vertes" -email="marc@vertes.org" -description="An experimental website on a solar phone" -link="https://dot.vertes.org" -date="20 th of June 2025" diff --git a/readme.md b/readme.md index 81a4acf..efdec65 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ A blog about programming and other stories. ## Posts -- [About this server](this-server) june 2025 +- 2025-06-20: [About this server](this-server) A web server on an old smartphone, solar powered. diff --git a/style.css b/style.css new file mode 100644 index 0000000..0f06d75 --- /dev/null +++ b/style.css @@ -0,0 +1,27 @@ +body { + max-width: 45rem; + margin: auto; + padding: 0.5em; + text-align: justify; + font-family: "Times New Roman", serif; +} +h1, h2, h3, h4 { + font-family: arial, sans; +} +h1 { + text-align: center; +} +pre { + padding: 1ch; + background-color: #f5f5f5; + overflow: auto; +} +img { + display: block; + margin: auto; + max-width: 100%; +} +footer { + text-align: center; + font-size: 0.8em; +} diff --git a/this-server/a_web_server_on_a_solar_phone.md b/this-server/a_web_server_on_a_solar_phone.md index ad2757b..45dabba 100644 --- a/this-server/a_web_server_on_a_solar_phone.md +++ b/this-server/a_web_server_on_a_solar_phone.md @@ -11,13 +11,12 @@ site that you are browsing right now is hosted on it. ## Hardware -The phone is an entry-level Motorola G7 Play, purchased in 2019 for 120€ or so, +The phone is an entry-level Motorola G7 Play, purchased in 2019, worth nothing today. It was used by my son for less than 2 years, then dormant since. The display is slighly shattered, but it doesn't matter, as I use it headless. I bought a small solar panel on Amazon, 10W produced by 2 plates of 17x17 cm. -Cost: 28€. I could probably get something less expensive. And that's it. The solar panel is just suspended vertically at a south window. The phone sits below, connected to the panel by a USB cable, in the shadow diff --git a/this-server/index.html b/this-server/index.html index 019b7db..3478cd4 100644 --- a/this-server/index.html +++ b/this-server/index.html @@ -1,40 +1,16 @@ - - + A web server on a solar phone - - - - - + + + Marc's Notes

A web server on a solar phone

I have this old low-cost phone which was the first one offered to my kid when he was 15 (he is now 21), before he moved to a more fashionable model. I noticed that without a SIM card, only on WIFI, the phone needed to be recharged not after 1 or 2 days, but only after 2 weeks! So this small device, plugged to a small solar panel, could be the perfect always-on personal web server. The site that you are browsing right now is hosted on it.

The server with its solar panel, and a cat

Hardware

-

The phone is an entry-level Motorola G7 Play, purchased in 2019 for 120€ or so, worth nothing today. It was used by my son for less than 2 years, then dormant since. The display is slighly shattered, but it doesn't matter, as I use it headless.

-

I bought a small solar panel on Amazon, 10W produced by 2 plates of 17x17 cm. Cost: 28€. I could probably get something less expensive.

+

The phone is an entry-level Motorola G7 Play, purchased in 2019, worth nothing today. It was used by my son for less than 2 years, then dormant since. The display is slighly shattered, but it doesn't matter, as I use it headless.

+

I bought a small solar panel on Amazon, 10W produced by 2 plates of 17x17 cm.

And that's it. The solar panel is just suspended vertically at a south window. The phone sits below, connected to the panel by a USB cable, in the shadow (do not put the phone directly under the sun, or closed without fresh air).

Software

The single purpose of this device is now to run a small standalone static web server. By using termux on top of Android, I can run a ssh server for remote access and Nginx, an efficient web server. I do not need to root the phone, as port redirection from my internet router compensate for the restriction of not using a port number below 1024.

@@ -45,4 +21,4 @@

Operation

It's too early to say. Lets see how it goes over time (a few months), and if a relatively old phone can find a second life and be used as an autonomous web server, running solely on free photons and electrons.

But for now, we are in june and the battery level is almost always at 100%.

-
From: Marc Vertes, 20 june 2025 +
From: Marc Vertes, 20 june 2025. Feedback diff --git a/this-server/meta b/this-server/meta new file mode 100644 index 0000000..0fce4ff --- /dev/null +++ b/this-server/meta @@ -0,0 +1,7 @@ +blog_title="Marc's Notes" +title="A web server on a solar phone" +author="Marc Vertes" +description="Hosting a web server on a solar powered phone" +link="dot.server.org/this-server" +date="20 june 2025" +date_rfc2822="Fri, 20 June 2025 12:00:00 +0200" diff --git a/this-server/meta.sh b/this-server/meta.sh deleted file mode 100644 index 60682cc..0000000 --- a/this-server/meta.sh +++ /dev/null @@ -1,6 +0,0 @@ -blog_title="Marc's Notes" -title="A web server on a solar phone" -author="Marc Vertes" -description="Hosting a web server on a solar powered phone" -date="20 june 2025" -date_rfc2822="Fri, 20 June 2025 12:00:00 +0200" -- cgit v1.2.3