oliverdavies.uk/content/node.d6363924-78ee-4086-8cf0-41e07c030fd4.yml

258 lines
11 KiB
YAML

uuid:
- value: d6363924-78ee-4086-8cf0-41e07c030fd4
langcode:
- value: en
type:
- target_id: daily_email
target_type: node_type
target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7
revision_timestamp:
- value: '2025-05-11T08:59:58+00:00'
revision_uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
revision_log: { }
status:
- value: true
uid:
- target_type: user
target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849
title:
- value: 'A reason why I like static site generators'
created:
- value: '2025-05-03T00:00:00+00:00'
changed:
- value: '2025-05-11T08:59:58+00:00'
promote:
- value: false
sticky:
- value: false
default_langcode:
- value: true
revision_translation_affected:
- value: true
path:
- alias: /daily/2025/05/03/like
langcode: en
body:
- value: |
<p>Static site generators <a href="/presentations/sculpin">like Sculpin</a> don't have a database like Drupal.</p>
<p>The files are the database.</p>
<p>In [my website repository][3], the <code>source/_presentations</code> directory contains the files for my presentation pages, so these could be considered the presentations table and rows.</p>
<p>But, because my content is in plain text files, they're very easy and quick to search in a text editor or on the command line using tools like <code>grep</code>.</p>
<p>It's very easy and fast for me to find an old daily email, blog post or article I've written when I need to.</p>
<p>This is also why I use <a href="/presentations/rst2pdf">rst2pdf for my presentation slides</a> and write them in reStructured text. It's very fast to find and re-use content.</p>
<h2 id="counting-my-presentations">Counting my presentations</h2>
<p>Another example is being able to quickly count the number of presentations I've given.</p>
<p>Here's an example of the front matter section from one of my presentations:</p>
<pre><code class="markdown">events:
- name: PHP South West
date: 2024-02-14
location: Bristol, UK
urls:
video: https://www.youtube.com/watch?v=axy6ltc9meA
demo: https://phpsw-sculpin-demo.oliverdavies.uk
- name: BrumPHP
date: 2024-05-23
location: Birmingham, UK
url: https://www.eventbrite.com/e/brumphp-23rd-may-2024-tickets-803037766577
- name: PHP Berkshire
date: 2024-08-28
location: Reading, UK
urls:
slides: /files/presentations/sculpin/php-berkshire.pdf
website: https://www.meetup.com/php-berkshire/events/301850284
- name: PHP Thames Valley
date: 2026-03-20
location: Oxford, UK
urls:
slides: /files/presentations/sculpin/php-thames-valley.pdf
code: https://code.oliverdavies.uk/opdavies/sculpin-demo/src/branch/php-thames-valley
website: https://www.meetup.com/php-thames-valley/events/305915971
</code></pre>
<p>Each presentation has a list of events, as most presentations I've given multiple times.</p>
<p>Each event has a <code>date</code> that I can extract with <code>grep</code>:</p>
<pre><code class="plain">grep -r "date:" source/_presentations/*.md
source/_presentations/tdd-test-driven-drupal.md: date: 2020-12-08
source/_presentations/tdd-test-driven-drupal.md: date: 2023-10-17
source/_presentations/tdd-test-driven-drupal.md: date: 2024-05-10
source/_presentations/tdd-test-driven-drupal.md: date: 2024-11-20
source/_presentations/test-drive-twig-with-sculpin.md: date: 2015-07-25
source/_presentations/things-you-should-know-about-php.md: date: 2019-01-28
source/_presentations/things-you-should-know-about-php.md: date: 2022-03-09
source/_presentations/things-you-should-know-about-php.md: date: 2023-01-12
source/_presentations/upgrading-your-site-drupal-9.md: date: 2020-09-02
source/_presentations/upgrading-your-site-drupal-9.md: date: 2020-09-23
source/_presentations/upgrading-your-site-drupal-9.md: date: 2021-04-22
source/_presentations/using-illuminate-collections-outside-laravel.md: date: 2017-12-21
source/_presentations/using-illuminate-collections-outside-laravel.md: date: 2018-08-28
source/_presentations/working-without-workspace.md: date: 2023-04-06
source/_presentations/working-with-workspace.md: date: 2020-08-11
source/_presentations/working-with-workspace.md: date: 2020-09-09
source/_presentations/working-with-workspace.md: date: 2021-02-02
</code></pre>
<p>To count them, I can add <code>| wc -l</code> to count the number of lines.</p>
<p>But what if I have presentations in the future I don't want to count?</p>
<p>To show just the dates, I can pipe the output to <code>awk</code> and only print the last item:</p>
<pre><code class="plain">grep -r "date:" source/_presentations/*.md | awk '{ print $NF }'
2020-12-08
2023-10-17
2024-05-10
2024-11-20
2015-07-25
2019-01-28
2022-03-09
2023-01-12
2020-09-02
2020-09-23
2021-04-22
2017-12-21
2018-08-28
2023-04-06
2020-08-11
2020-09-09
2021-02-02
</code></pre>
<p>I can sort them by adding <code>| sort</code>, but that doesn't matter in this case.</p>
<p>To remove any future presentations, I can pass the current date to <code>awk</code>, filter based on the date and count the number of lines in the result:</p>
<pre><code class="plain">grep -r "date:" source/_presentations/*.md | awk -v today="$(date +%Y-%m-%d)" '{ if ($NF &lt; today) print $NF }' | wc -l
104
</code></pre>
<p>This isn't how I'm calculating this on my website (I'm using a <a href="/daily/2025/05/02/extend">custom Twig extension in Sculpin</a> for that), but this is an example of how multiple command line utilities can work together to perform a task - made possible using the static files from my website.</p>
format: full_html
processed: |
<p>Static site generators <a href="/presentations/sculpin">like Sculpin</a> don't have a database like Drupal.</p>
<p>The files are the database.</p>
<p>In [my website repository][3], the <code>source/_presentations</code> directory contains the files for my presentation pages, so these could be considered the presentations table and rows.</p>
<p>But, because my content is in plain text files, they're very easy and quick to search in a text editor or on the command line using tools like <code>grep</code>.</p>
<p>It's very easy and fast for me to find an old daily email, blog post or article I've written when I need to.</p>
<p>This is also why I use <a href="/presentations/rst2pdf">rst2pdf for my presentation slides</a> and write them in reStructured text. It's very fast to find and re-use content.</p>
<h2 id="counting-my-presentations">Counting my presentations</h2>
<p>Another example is being able to quickly count the number of presentations I've given.</p>
<p>Here's an example of the front matter section from one of my presentations:</p>
<pre><code class="markdown">events:
- name: PHP South West
date: 2024-02-14
location: Bristol, UK
urls:
video: https://www.youtube.com/watch?v=axy6ltc9meA
demo: https://phpsw-sculpin-demo.oliverdavies.uk
- name: BrumPHP
date: 2024-05-23
location: Birmingham, UK
url: https://www.eventbrite.com/e/brumphp-23rd-may-2024-tickets-803037766577
- name: PHP Berkshire
date: 2024-08-28
location: Reading, UK
urls:
slides: /files/presentations/sculpin/php-berkshire.pdf
website: https://www.meetup.com/php-berkshire/events/301850284
- name: PHP Thames Valley
date: 2026-03-20
location: Oxford, UK
urls:
slides: /files/presentations/sculpin/php-thames-valley.pdf
code: https://code.oliverdavies.uk/opdavies/sculpin-demo/src/branch/php-thames-valley
website: https://www.meetup.com/php-thames-valley/events/305915971
</code></pre>
<p>Each presentation has a list of events, as most presentations I've given multiple times.</p>
<p>Each event has a <code>date</code> that I can extract with <code>grep</code>:</p>
<pre><code class="plain">grep -r "date:" source/_presentations/*.md
source/_presentations/tdd-test-driven-drupal.md: date: 2020-12-08
source/_presentations/tdd-test-driven-drupal.md: date: 2023-10-17
source/_presentations/tdd-test-driven-drupal.md: date: 2024-05-10
source/_presentations/tdd-test-driven-drupal.md: date: 2024-11-20
source/_presentations/test-drive-twig-with-sculpin.md: date: 2015-07-25
source/_presentations/things-you-should-know-about-php.md: date: 2019-01-28
source/_presentations/things-you-should-know-about-php.md: date: 2022-03-09
source/_presentations/things-you-should-know-about-php.md: date: 2023-01-12
source/_presentations/upgrading-your-site-drupal-9.md: date: 2020-09-02
source/_presentations/upgrading-your-site-drupal-9.md: date: 2020-09-23
source/_presentations/upgrading-your-site-drupal-9.md: date: 2021-04-22
source/_presentations/using-illuminate-collections-outside-laravel.md: date: 2017-12-21
source/_presentations/using-illuminate-collections-outside-laravel.md: date: 2018-08-28
source/_presentations/working-without-workspace.md: date: 2023-04-06
source/_presentations/working-with-workspace.md: date: 2020-08-11
source/_presentations/working-with-workspace.md: date: 2020-09-09
source/_presentations/working-with-workspace.md: date: 2021-02-02
</code></pre>
<p>To count them, I can add <code>| wc -l</code> to count the number of lines.</p>
<p>But what if I have presentations in the future I don't want to count?</p>
<p>To show just the dates, I can pipe the output to <code>awk</code> and only print the last item:</p>
<pre><code class="plain">grep -r "date:" source/_presentations/*.md | awk '{ print $NF }'
2020-12-08
2023-10-17
2024-05-10
2024-11-20
2015-07-25
2019-01-28
2022-03-09
2023-01-12
2020-09-02
2020-09-23
2021-04-22
2017-12-21
2018-08-28
2023-04-06
2020-08-11
2020-09-09
2021-02-02
</code></pre>
<p>I can sort them by adding <code>| sort</code>, but that doesn't matter in this case.</p>
<p>To remove any future presentations, I can pass the current date to <code>awk</code>, filter based on the date and count the number of lines in the result:</p>
<pre><code class="plain">grep -r "date:" source/_presentations/*.md | awk -v today="$(date +%Y-%m-%d)" '{ if ($NF &lt; today) print $NF }' | wc -l
104
</code></pre>
<p>This isn't how I'm calculating this on my website (I'm using a <a href="/daily/2025/05/02/extend">custom Twig extension in Sculpin</a> for that), but this is an example of how multiple command line utilities can work together to perform a task - made possible using the static files from my website.</p>
summary: null
field_daily_email_cta: { }