🚀 I just published a short guide explaining how to upgrade PostgreSQL 🐘 from version 15 to 16 just after an upgrade to Ubuntu 24.04 LTS (Noble Numbat) 🦘
Bienenhotels: Für welche Arten taugen sie eigentlich? Es gibt einfache Möglichkeiten, Marke Eigenbau, spezialisierten Wildbienen im Garten oder auf dem Balkon etwas zu bieten 🐝
Hot on the heels of yesterday's post, I've now made all of this blog available in text-only mode. Simply append .txt to the URl of any page and you'll get back the contents in plain UTF-8 text. No formatting, no images (although you can see the alt text), no nothing! Front page https://shkspr.mobi/blog/.txt This blog […]
Hot on the heels of yesterday's post, I've now made all of this blog available in text-only mode.
Simply append .txt to the URl of any page and you'll get back the contents in plain UTF-8 text. No formatting, no images (although you can see the alt text), no nothing!
This was slightly tricky to get right! While there might be an easier way to do it, here's how I got it to work.
Firstly, when someone requests /whatever.txt, WordPress is going to 404 - because that page doesn't exist. So, my theme's functions.php, detects any URls which end in .txt and redirects it to a different template.
// Theme Switcheradd_filter( "template_include", "custom_theme_switch" );function custom_theme_switch( $template ) { // What was requested? $requested_url = $_SERVER["REQUEST_URI"]; // Check if the URL ends with .txt if ( substr( $requested_url, -4 ) === ".txt") { // Get the path to the custom template $custom_template = get_template_directory() . "/templates/txt-template.php"; // Check if the custom template exists if ( file_exists( $custom_template ) ) { return $custom_template; } } // Return the default template return $template;}
The txt-template.php file is more complex. It takes the requested URl, strips off the .txt, matches it against the WordPress rewrite rules, and then constructs the WP_Query which would have been run if the .txt wasn't there.
// Run the query for the URl requested$requested_url = $_SERVER['REQUEST_URI']; // This will be /whatever$blog_details = wp_parse_url( home_url() ); // Get the blog's domain to construct a full URl$query = get_query_for_url( $blog_details["scheme"] . "://" . $blog_details["host"] . substr( $requested_url, 0, -4 ));function get_query_for_url( $url ) { // Get all the rewrite rules global $wp_rewrite; // Get the WordPress site URL path $site_path = parse_url( get_site_url(), PHP_URL_PATH ) . "/"; // Parse the requested URL $url_parts = parse_url( $url ); // Remove the domain and site path from the URL // For example, change `https://example.com/blog/2024/04/test` to just `2024/04/test` $url_path = isset( $url_parts['path'] ) ? str_replace( $site_path, '', $url_parts['path'] ) : ''; // Match the URL against WordPress rewrite rules $rewrite_rules = $wp_rewrite->wp_rewrite_rules(); $matched_rule = false; foreach ( $rewrite_rules as $pattern => $query ) { if ( preg_match( "#^$pattern#", $url_path, $matches ) ) { $matched_rule = $query; break; } } // Replace each occurrence of $matches[N] with the corresponding value foreach ( $matches as $key => $value ) { $matched_rule = str_replace( "$matches[{$key}]", $value, $matched_rule ); } // Turn the query string into a WordPress query $query_params = array(); parse_str( parse_url( $matched_rule, PHP_URL_QUERY), $query_params ); // Construct a new WP_Query object using the extracted query parameters $query = new WP_Query($query_params); // Return the result of the query return $query;}
When you buy a TUXEDO, you don't just buy a laptop - we also provide a wide range of help articles and instructions that are constantly being updated and expanded.
One of the best HTTP clients is the open source tool curl. With ongoing development and continuously new updates, it is worth getting everything out of this powerful tool!
🆕 blog! “Server-Side Rendering of Embedded Markdown Code Snippets in WordPress”
Because I'm a grumpy old man, I don't use Gutenberg or Block themes on my WordPress. Instead, I write everything in Markdown. When I write code snippets in Markdown, they look like this: ```php $a = 1; echo $a; if ($a < 5) { // Do Something return thing( $a, true …
But I want to render that with code highlighting. I was using the Prismatic Plugin. It is excellent and very customisable. But it uses JavaScript to do the code highlighting. I want to respect my readers' time and battery life; so I'm trying to reduce my dependency on Client-Side rendering.
I've switched to a modified version of WP-GeSHi-Highlight. That turns the above Markdown into:
Secondly, in order to make any changes to the default styles of the highlighter, you need to add the bundled wp-geshi-highlight.css file into your style directory. The plugin will use that if it exists - so you can change font size and padding to be the same as your main theme.
No line-numbers. The plugin looks for something like line="13", but there's no way to add that in Markdown.
GeSHi hasn't received style updates on some languages for quite some time. It hasn't received any significant update since 2019. Which means bugs and security issues are likely.
Language definitions are quite strict. You can use javascript but not json.
The plugin doesn't have any options - nor an easy way to override its settings. So I've monkeypatched everything above. If the plugin updates, I'll need to change my code.
Rereading @pluralistic 's "Little Brother" last week brought back great memories of staying up way too late at night reading #USENET#HOWTO s and #FAQ s .. and then doing some sketchy shit with #linux
I use a self-built WordPress theme for this blog. I also use a variety of self-developed WordPress plugins for various enhancements. I used to publish these plugins, but I get terribly confused by the SVN shenanigans involved, and they weren't used by many people, so I stopped.
Recently, I've been moving all my plugin code into my theme. This is sort-of-but-not-quite a MonoRepo.
I've also tried to move away, as far as possible, from using other people's plugins. Most of the ones I had were single-shot plugins which did one thing and needed the minimum amount of configuration. So I learned from their code and re-implemented it into my theme.
This isn't quite digital-homesteading. I'm not rolling my own crypto, or building my own CMS. I'm just taking back a little control, learning how things work, and enjoying the busy-work of Digital Gardening.
I don't know if this is a good idea. It means I don't get security updates if my knock-off code is vulnerable. I don't get new features. But I also don't have to trust that a 3rd-party developer isn't going to screw up (I can screw up on my own, thank-you-very-much!). I've had a few bad experiences with plugins which suddenly stopped working, or had abusive behaviour.
I put new functionality into a file with a descriptive name, for example related-posts.php and I save it in my-theme/includes/.
In my WordPress's theme, I add this to functions.php:
// Load all the files$includes_path = get_template_directory() . "/includes/";foreach ( new DirectoryIterator( $includes_path ) as $fileInfo ) { if( $fileInfo->isDot() ) continue; // Ignore . and .. if( $fileInfo->getExtension() != "php" ) continue; // Only load PHP require_once( get_template_directory() . "/includes/" . $fileInfo->getFilename() );}
That loads all the .php files from /includes/.
I have no idea how performant this is. I have some fairly aggressive caching plugins which should minimise any slowness - and they're not part of my MonoRepo.
Every game starts with an idea. But how does it get from conception to release❓
In this book, author Alexey Savchenko has put together a practical guide, based on his 20+ years in #GameDev, to help you avoid the common pitfalls and deliver on your idea!
I think, for me, much like EDLIN, it's pretty much always been a matter of knowing that it was the default editor available in every incarnation of #UNIX and #Linux since, ... I dunno, ... 4.2BSD or so?
Perhaps I should say vi, and in DOS I don't really recall when EDIT.COM supplanted #EDLIN, but do feel free to checkout my friend's more modern #FREDLIN in the link above. h/t to @dheadshot for creating a POSIX interpretation of that classic utility from the days when disk drives talked to you and diskettes shimmied...
Also, These #Vim memes are some of the funnest elbows to the ribs of the person sitting next to you we can all enjoy together... unless, unless, Oh my gawd am I on Drugs?
Here's another one for folks to add to their collections, for foshizzles and giggles, of course, and we all can haz #Cheezburgerz! 🍔
Kindest regards, and thank you for some of the very best cookbook style #tuts, #HowTo's, and introspectives for the UNIX / Linux / FOSS world on the Internet :)