Dublin Library

The Publishing project

Using Gettext based translations in Node

When working with WordPress, one of the things I enjoyed was how easy it made it to use Gettext-based translation tooling and functionality to localize themes and plugins. I was thinking that it would be nice if there was an equivalent toolset for Javascript. node-gettexthttps://www.npmjs.com/package/node-gettext seems to fit the bill nicely. It provides facilities to load and work with existing PO files and it provides the basic tooling that we need to work directly with PO files generate with other tools. Even though Node now supports ESM and their related methods I'm sticking to CommonJS for a while longer so...

Continue reading →

Leveraging local fonts

Note This feature needs an Origin Trial Keyhttps://web.dev/origin-trials/ for your origin. If you choose not to go for an Origin Trial then you and your users will need to enable the Font Access APIs flag font-access in chrome://flags and restart the browser. The web has had custom font capabilities from very early on in the history of CSS. CSS introduced @font-face in 1998 as part of CSS 2. It allowed developers to link to font files and use them to display content on the web. As with many things in the early days of the web, different browser vendors decided...

Continue reading →

(Re)learning how to use VoiceOver

I was rereading I Used The Web For A Day Using A Screen Readerhttps://www.smashingmagazine.com/2018/12/voiceover-screen-reader-web-apps/ and realized that it's been a while since I last used VoiceOver the built-in screen reader for Mac to proof the content of my posts and pages. I said "fine, let's fire it up and listen to what the page I was reading sounds like". It wasn't as easy as I thought as I've forgotten most of the commands that I used to navigate content with Voiceover. So, rather than have to commit this to memory I'll post it here and generate a PDF of the...

Continue reading →

CSS Media Queries in Javascript

Since a lot of work we do in CSS we actually do in Javascript, I thought it would be good to research how we can do media queries in JS too. There are two ways to work with media queries. The first one is to do something with the condition when the script first loads. In this example, create a media query using window.matchMediahttps://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia to determine if the document matched the specified media query. js // Define the query const mediaQuery = window.matchMedia"max-width: 768px"; // Create a media condition that // targets smaller than 768px wide const mediumSizeQuery = window.matchMedia"max-width:...

Continue reading →

Writing topic-based content

Topic-based documentation is content broken down into topics; small reusable chunks of content that can be reused in multiple documents. I try my best to write as if the document was topic-based. Some of the advantages I see: - Topic-based authoring makes you think about the content you write. The content is usually more focused - Users can go straight to the section with the information they need, and it should make sense on its own with little or no outside references - It allows you to tailor material for different audiences - Most topic-based authoring tools let you use...

Continue reading →

Linting WordPress PHP files

While I've been doing WordPress theme development I've also been working on getting PHPCS PHP Code Snifferhttps://github.com/squizlabs/PHPCodeSniffer to work properly on my projects. I think I've finally got it. As usual, I was making things too hard on myself and it ended up being far easier to set up and use. The first tool we need is Composerhttps://getcomposer.org/ to install and manage dependencies. Think of Composer as the PHP version of NPM. Since I'm working on a Mac, I chose to install it with Homebrewhttps://brew.sh/ using the command below: bash brew install composer The next step is to install PHPCS...

Continue reading →

Playing with the filesystem API

There have been multiple attempts at getting a Filesystem API on the web. The one I'm referring to in this post is a Chromium-only feature available without a flag since Chrome 86, not the old-style API. This is also different from the API available to Chrome extensions. I used a standard HTML5 Boilerplate document. We add a single CSS class inside a style element to hide elements. css .hidden { display: none; } The HTML for the demo is simple. We create a text area and two buttons and assign IDs to each; this will make it easier to manipulate...

Continue reading →

Running Lighthouse Programmatically

In addition to the DevTools menu and the Chrome extension and the Lighthouse CLI, there are ways to use Lighthouse programmatically in ways that would be too time-consuming to do with the lighthouse tools already available. The simplest example will run all Lighthouse reports for the given URL using the default options for Lighthouse. js function launchChromeAndRunLighthouseurl, opts, config = null { return chromeLauncher.launch{chromeFlags: opts.chromeFlags} .thenchrome => { opts.port = chrome.port; return lighthouseurl, opts, config .thenresults => { return chrome.kill .then => results.lhr }; }; } The lighthouse configurations docshttps://github.com/GoogleChrome/lighthouse/blob/master/docs/configuration.md provides a detailed description of all the options that you...

Continue reading →

CSS/JS Coverage in Chrome DevTools

Since version 59, Chrome DevTools ship with a coverage analyzer that will tell you how much of the Javascript you load is actually used on your pages. This is important because, if the code is yours, you can eliminate dead weight and reduce the size of your site's styles and scripts. Running Coverage Analysis Running coverage from Chrome DevTools is fairly straight forward. Open DevTools Command + Option + I on Mac or Control + Shift + I on Windows and look at the bottom of the DevTools window, there should be a coverage tab. When you select the coverage...

Continue reading →

Passing data to WordPress template files

The template loading functions get\header, get\template\part, etc. have a new $args argument. So now you can pass an array’s of data to the templates. The idea is that we can now pass an object with additional, arbitrary, information for the template to use. In this example, we load a hypothetical foo template part and pass an array of items as the third parameter on the function call. php 'user', 'arbitrarydata' => array 'foo' => 'baz', 'bar' => true, , ; We can then use this arbitrary data on the template. The example uses the class attribute from the $args array...

Continue reading →