Skip to content

Commit

Permalink
Revert CDN asset changes (#429)
Browse files Browse the repository at this point in the history
* Revert "Global Fonts: Fix the inline URLs after #424."
* Revert "Add CDN versioning for fonts (#424)"
* Revert "Add a CDNise mu-plugin (#173)"
  • Loading branch information
dd32 committed Aug 25, 2023
1 parent f2e8309 commit cb5a052
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 307 deletions.
32 changes: 7 additions & 25 deletions bin/font-subset.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@
*/
import { spawn } from 'child_process';
import path from 'path';
import { existsSync, renameSync, readFileSync, writeFile } from 'fs';
import { createHash } from 'crypto';

function generateHash( filename ) {
filename = path.join( __dirname, `output/${ filename }` )
/*
* Magic Number 12, See get_file_hash()
* https://github.com/WordPress/wporg-mu-plugins/blob/trunk/mu-plugins/cdn/assets.php
*/
return createHash('sha1').update( readFileSync( filename ), 'binary').digest('hex').substring( 0, 12 );
}
import { renameSync, writeFile } from 'fs';

const alphabets = [
{
Expand Down Expand Up @@ -99,25 +89,17 @@ let cssCode = '';
// Create our font face rules
// This would need to be modified for other weights and styles
alphabets.forEach( ( alphabet ) => {
let filename = `${ fontFileName }-${ alphabet.name }.woff2`;

if ( ! existsSync( filename ) ) {
return;
}

let hash = generateHash( filename );

cssCode += `
/* ${ alphabet.name } */
@font-face {
@font-face {
font-family: ${ fontFamily };
font-weight: ${ fontWeight };
font-style: ${ fontStyle };
font-display: swap;
src: url(./${ fontFinalDir }/${ filename }?ver=${ hash }) format("woff2");
unicode-range: ${ alphabet.unicodeRange };
}
`;
font-display: swap;
src: url(./${ fontFinalDir }/${ fontFileName }-${ alphabet.name }.woff2) format("woff2");
unicode-range: ${ alphabet.unicodeRange };
}
`;
} );

// Determine where to save our file
Expand Down
188 changes: 0 additions & 188 deletions mu-plugins/cdn/assets.php

This file was deleted.

21 changes: 4 additions & 17 deletions mu-plugins/global-fonts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,9 @@ function relative_to_absolute_urls( $editor_settings ) {
}

foreach ( $editor_settings['styles'] as $i => $style ) {
if (
str_contains( $style['css'], './Inter' ) ||
str_contains( $style['css'], './EB-Garamond' ) ||
str_contains( $style['css'], './CourierPrime' ) ||
str_contains( $style['css'], './IBMPlexMono' )
) {
$style['css'] = preg_replace_callback(
'!url\(./(?P<path>[^)]+)\)!i',
function( $m ) {
return "url(" . plugins_url( $m['path'], __FILE__ ) . ")";
},
$style['css']
);

if ( str_contains( $style['css'], './Inter' ) || str_contains( $style['css'], './EB-Garamond' ) ) {
$url = plugins_url( '', __FILE__ );
$style['css'] = str_replace( 'url(./', "url($url/", $style['css'] );
$editor_settings['styles'][ $i ] = $style;
}
}
Expand Down Expand Up @@ -210,7 +199,5 @@ function get_font_url( $font, $subset ) {
return false;
}

$font_version = filemtime( __DIR__ . '/' . $filepath );

return plugins_url( "{$filepath}?ver={$font_version}", __FILE__ );
return plugins_url( $filepath, __FILE__ );
}

0 comments on commit cb5a052

Please sign in to comment.