diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-12-29 23:59:59 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-12-29 23:59:59 +0100 |
| commit | 0c895d25be27693cd8ecf742305673984e07dfd1 (patch) | |
| tree | f7c42c306e919ede80330883558c1f349609f1a5 /src/blog/2022-12-30-blog-ready | |
| parent | 57f783cdfbdfbfd3dfa30da9adb7bba88da0ecd5 (diff) | |
| download | sebastiano.tronto.net-0c895d25be27693cd8ecf742305673984e07dfd1.tar.gz sebastiano.tronto.net-0c895d25be27693cd8ecf742305673984e07dfd1.zip | |
New blog post
Diffstat (limited to 'src/blog/2022-12-30-blog-ready')
| -rw-r--r-- | src/blog/2022-12-30-blog-ready/blog-ready.md | 52 | ||||
| -rw-r--r-- | src/blog/2022-12-30-blog-ready/pc-planner.jpg | bin | 0 -> 6497789 bytes |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/blog/2022-12-30-blog-ready/blog-ready.md b/src/blog/2022-12-30-blog-ready/blog-ready.md new file mode 100644 index 0000000..144e5e2 --- /dev/null +++ b/src/blog/2022-12-30-blog-ready/blog-ready.md | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | # Getting my blog ready for 2023 | ||
| 2 | |||
| 3 | My first year of blogging is about to end, and I am happy with what | ||
| 4 | I wrote. I wanted to write at least one post every month, and I did. I | ||
| 5 | intend to keep this pace next year, but I want to make this easier by | ||
| 6 | writing shorter posts from time to time. This is not a trivial task: | ||
| 7 | I found out that writing good *short* content is harder than writing | ||
| 8 | good *long* content! | ||
| 9 | |||
| 10 | But if I keep writing, [my blogs's index page](../) is going to become | ||
| 11 | messy at some point! It would be nice to divide these posts by year... | ||
| 12 | |||
| 13 | ## Adding year sections to my blog index | ||
| 14 | |||
| 15 | Very easy: in my | ||
| 16 | [build.sh](https://git.tronto.net/sebastiano.tronto.net/file/build.sh.html) | ||
| 17 | script that I run to | ||
| 18 | [build my website](../2022-08-14-website), there is a | ||
| 19 | [`makeblog()`](https://git.tronto.net/sebastiano.tronto.net/file/build.sh.html#l52) | ||
| 20 | function that takes care of building the index page and RSS feed for my blog. | ||
| 21 | |||
| 22 | It is enough to add the following lines inside its main loop: | ||
| 23 | |||
| 24 | ``` | ||
| 25 | thisyear=$(echo $d | sed 's/-.*//') | ||
| 26 | if [ "$thisyear" != "$lastyear" ]; then | ||
| 27 | printf "\n## $thisyear\n\n" >> $bf | ||
| 28 | lastyear=$thisyear | ||
| 29 | fi | ||
| 30 | ``` | ||
| 31 | |||
| 32 | And that's it! These few lines introduce two new variables, `thisyear` | ||
| 33 | and `lastyear`, that keep track of the years of the last and next blog | ||
| 34 | post that the loop is scanning. If there was a year change, a new line | ||
| 35 | with the current year is added, and the `lastyear` variable is updated. | ||
| 36 | The first line refers to a variable `d` that holds the date of the | ||
| 37 | current post in `yyyy-mm-dd` format. | ||
| 38 | |||
| 39 | A last note on the variables: if you are familiar with other programming | ||
| 40 | languages, you might wonder where the variable `lastyear` is initialized. | ||
| 41 | After all, I am using it in the `if` statement's condition, so it must | ||
| 42 | be initialized outside of its body, right? | ||
| 43 | |||
| 44 | Actually, no. The shell's variable scoping does not work like in C or | ||
| 45 | similar languages, and a variable initialized inside a block is also | ||
| 46 | visibile outside of it. Moreover, un-initialized variables evaluate to | ||
| 47 | the empty string, so the first time the condition is checked it correctly | ||
| 48 | determines that the current year is different from the last. | ||
| 49 | |||
| 50 | This was my last UNIX shell tip for this year. Stay tuned for more! | ||
| 51 | |||
| 52 |  | ||
diff --git a/src/blog/2022-12-30-blog-ready/pc-planner.jpg b/src/blog/2022-12-30-blog-ready/pc-planner.jpg new file mode 100644 index 0000000..8fb52e5 --- /dev/null +++ b/src/blog/2022-12-30-blog-ready/pc-planner.jpg | |||
| Binary files differ | |||
