Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time format with client side date parsing #415

Merged
merged 33 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
93160a3
Add wporg/time block
adamwoodnz Jul 11, 2023
ff37454
Remove debug
adamwoodnz Jul 11, 2023
be048ab
Stop parsing content if empty
adamwoodnz Jul 11, 2023
8c87c3f
Remove usage of register_block_type as this isn't a block
adamwoodnz Jul 16, 2023
f8058d6
Fix phpcs errors
adamwoodnz Jul 16, 2023
f82d9c6
Enqueue frontend script if required rather than rendering inline
adamwoodnz Jul 17, 2023
e6eb98b
Change to semantic elements for time on frontend
adamwoodnz Jul 17, 2023
c3f936f
Fix transform_times bail out logic
adamwoodnz Jul 17, 2023
018f389
Use Gutenberg non block example approach for registering and enqueuin…
adamwoodnz Jul 17, 2023
0dd43dc
Remove unused helper
adamwoodnz Jul 17, 2023
8eb9242
Fix bail out logic for no time elements
adamwoodnz Jul 18, 2023
11329c5
Revert "Use Gutenberg non block example approach for registering and …
adamwoodnz Jul 18, 2023
eb1c15c
Use Moment to parse the date description and add it to the time eleme…
adamwoodnz Jul 18, 2023
1fa0b11
Replace php dom manipulation with js
adamwoodnz Jul 18, 2023
19e6e62
Update descriptions to specify input format
adamwoodnz Jul 18, 2023
be3f4f7
Update docs
adamwoodnz Jul 18, 2023
10a3340
Skip parsing if format is being deactivated
adamwoodnz Jul 18, 2023
78d8732
Replace Moment usage with locutus
adamwoodnz Jul 21, 2023
8b595e8
Keep time element within link
adamwoodnz Jul 21, 2023
98cfec0
Use wp_script_add_data to output view script in footer
adamwoodnz Jul 24, 2023
56efe04
Rename view script
adamwoodnz Jul 24, 2023
33a49c7
Fix regex to allow negative time offsets
adamwoodnz Jul 25, 2023
3046990
Allow time tags in post content
adamwoodnz Jul 25, 2023
ff22ba4
Execute the view script once all resources have loaded
adamwoodnz Jul 25, 2023
e8884af
Update descriptions
adamwoodnz Jul 25, 2023
af2572a
Style the time formatted strings
adamwoodnz Jul 31, 2023
2ff4962
Add block attribute config
adamwoodnz Aug 1, 2023
2b34bd6
Remove the format if the time description is changed
adamwoodnz Aug 1, 2023
82d9b2c
Handle multiple times in the selected block
adamwoodnz Aug 1, 2023
4304601
Use dotted style for the underline
adamwoodnz Aug 2, 2023
ea1dad6
Add partial support for the Site Editor
adamwoodnz Aug 21, 2023
b3a0b0e
Update yoast/phpunit-polyfills to satisfy CI
adamwoodnz Aug 21, 2023
fa16768
Fix editor styles in Safari
adamwoodnz Aug 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"wp-coding-standards/wpcs": "2.*",
"wp-phpunit/wp-phpunit": "~6.0",
"wporg/wporg-repo-tools": "dev-trunk",
"yoast/phpunit-polyfills": "^1.0"
"yoast/phpunit-polyfills": "^1.1"
},
"config": {
"allow-plugins": {
Expand Down
107 changes: 54 additions & 53 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions mu-plugins/blocks/time/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Format Name: Time
* Description: Attempts to parse a time string like 'Tuesday, April 5th, at 15:00 UTC' relative to the post date,
* and creates a format that shows it in the viewer's local time zone.
*
* @package wporg
*/

namespace WordPressdotorg\MU_Plugins\Time;

add_action( 'init', __NAMESPACE__ . '\init' );

/**
* Enqueues the scripts for the Time format in the block editor and frontend using the metadata loaded from the `block.json` file.
*/
function init() {
// Add the JS script to add the Time formatting option to the toolbar. The dependencies are autogenerated in block.json,
// and can be read with `wp_json_file_decode` & `register_block_script_handle.
$metadata_file = __DIR__ . '/build/block.json';
$metadata = wp_json_file_decode( $metadata_file, array( 'associative' => true ) );
$metadata['file'] = $metadata_file;

$editor_script_handle = register_block_script_handle( $metadata, 'editorScript' );
add_action(
'enqueue_block_assets',
function() use ( $editor_script_handle ) {
if ( wp_should_load_block_editor_scripts_and_styles() && is_admin() ) {
wp_enqueue_script( $editor_script_handle );
}
}
);

$view_script_handle = register_block_script_handle( $metadata, 'viewScript' );
add_action(
'wp_enqueue_scripts',
function() use ( $view_script_handle ) {
if ( ! is_admin() ) {
wp_enqueue_script( $view_script_handle );
wp_script_add_data( $view_script_handle, 'group', 1 );
}
}
);

add_filter( 'wp_kses_allowed_html', __NAMESPACE__ . '\add_time_to_allowed_html', 10, 2 );
}

/**
* Adds the `time` tag to the allowed HTML tags for the block editor.
*
* @param array $allowed_tags Allowed tags, attributes, and/or entities.
* @param string $context Context to judge allowed tags by.
* @return array Allowed tags, attributes, and/or entities.
*/
function add_time_to_allowed_html( $allowed_tags, $context ) {
if ( 'post' === $context ) {
$allowed_tags['time'] = array(
'class' => true,
'data-iso' => true,
'datetime' => true,
);
}

return $allowed_tags;
}
Loading