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 identifier to JSON-LD metadata #3007

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/Metadata/class-metadata-renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function render_metadata( string $meta_type ): void {

// Insert JSON-LD or repeated metas.
if ( 'json_ld' === $meta_type ) {
echo '<script type="application/ld+json">' . wp_json_encode( $metadata ) . '</script>';
echo '<script type="application/ld+json" class="wp-parsely-metadata">' . wp_json_encode( $metadata ) . '</script>';
} else {
// Assume `meta_type` is `repeated_metas`.
$parsely_post_type = $this->parsely->convert_jsonld_to_parsely_type( $metadata['@type'] ?? '' );
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Endpoints/RestMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function test_get_rendered_meta_json_ld(): void {
$this->go_to( (string) $this->get_permalink( $post_id ) );

$meta_string = self::$rest->get_rendered_meta( 'json_ld' );
$expected = '<script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"NewsArticle","headline":"My test_get_rendered_meta_json_ld title","url":"http:\/\/example.org\/?p=' . $post_id . '","mainEntityOfPage":{"@type":"WebPage","@id":"http:\/\/example.org\/?p=' . $post_id . '"},"thumbnailUrl":"","image":{"@type":"ImageObject","url":""},"articleSection":"Uncategorized","author":[],"creator":[],"publisher":{"@type":"Organization","name":"Test Blog","logo":""},"keywords":[],"dateCreated":"' . $date . '","datePublished":"' . $date . '","dateModified":"' . $date . '"}</script>';
$expected = '<script type="application/ld+json" class="wp-parsely-metadata">{"@context":"https:\/\/schema.org","@type":"NewsArticle","headline":"My test_get_rendered_meta_json_ld title","url":"http:\/\/example.org\/?p=' . $post_id . '","mainEntityOfPage":{"@type":"WebPage","@id":"http:\/\/example.org\/?p=' . $post_id . '"},"thumbnailUrl":"","image":{"@type":"ImageObject","url":""},"articleSection":"Uncategorized","author":[],"creator":[],"publisher":{"@type":"Organization","name":"Test Blog","logo":""},"keywords":[],"dateCreated":"' . $date . '","datePublished":"' . $date . '","dateModified":"' . $date . '"}</script>';
self::assertSame( $expected, $meta_string );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/UI/MetadataRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function test_render_metadata_json_ld(): void {
*/
$out = ob_get_clean();

self::assertStringContainsString( '<script type="application/ld+json">', $out );
self::assertStringContainsString( '<script type="application/ld+json" class="wp-parsely-metadata">', $out );
self::assertStringContainsString( '</script>', $out );
}

Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/specs/front-end-metadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test.describe( 'Front end metadata insertion', () => {

const content = await page.content();

expect( content ).toContain( '<script type="application/ld+json">{"@context":"https:\\/\\/schema.org","@type":"WebPage","headline":"wp-parsely","url":"http:\\/\\/localhost:8889"}</script>' );
expect( content ).toContain( '<script type="application/ld+json" class="wp-parsely-metadata">{"@context":"https:\\/\\/schema.org","@type":"WebPage","headline":"wp-parsely","url":"http:\\/\\/localhost:8889"}</script>' );
expect( content ).not.toContain( '<meta name="parsely-title" ' );
} );

Expand All @@ -67,7 +67,7 @@ test.describe( 'Front end metadata insertion', () => {

const content = await page.content();

expect( content ).toContain( '<script type="application/ld+json">' );
expect( content ).toContain( '<script type="application/ld+json" class="wp-parsely-metadata">' );
expect( content ).toContain( '{"@context":"https:\\/\\/schema.org","@type":"NewsArticle","headline":"Hello world!","url":"http:\\/\\/localhost:8889\\/?p=1","mainEntityOfPage":{"@type":"WebPage","@id":"http:\\/\\/localhost:8889\\/?p=1"},"thumbnailUrl":"","image":{"@type":"ImageObject","url":""},"articleSection":"Uncategorized","author":[{"@type":"Person","name":"admin"}],"creator":["admin"],"publisher":{"@type":"Organization","name":"wp-parsely","logo":""},"keywords":[],"' );
expect( content ).not.toContain( '<meta name="parsely-title" ' );
} );
Expand All @@ -82,7 +82,7 @@ test.describe( 'Front end metadata insertion', () => {

const content = await page.content();

expect( content ).toContain( '<script type="application/ld+json">' );
expect( content ).toContain( '<script type="application/ld+json" class="wp-parsely-metadata">' );
expect( content ).toContain( '{"@context":"https:\\/\\/schema.org","@type":"WebPage","headline":"Sample Page","url":"http:\\/\\/localhost:8889\\/?page_id=2","mainEntityOfPage":{"@type":"WebPage","@id":"http:\\/\\/localhost:8889\\/?page_id=2"},"thumbnailUrl":"","image":{"@type":"ImageObject","url":""},"articleSection":"Uncategorized","author":[{"@type":"Person","name":"admin"}],"creator":["admin"],"publisher":{"@type":"Organization","name":"wp-parsely","logo":""},"keywords":[],"' );
expect( content ).not.toContain( '<meta name="parsely-title" ' );
} );
Expand All @@ -107,7 +107,7 @@ test.describe( 'Front end metadata insertion', () => {
expect( content ).not.toMatch( /<meta name="parsely-pub-date" content=".*Z">/ );
expect( content ).not.toContain( '<meta name="parsely-section" content="Uncategorized">' );
expect( content ).not.toContain( '<meta name="parsely-author" content="admin">' );
expect( content ).not.toContain( '<script type="application/ld+json">' );
expect( content ).not.toContain( '<script type="application/ld+json" class="wp-parsely-metadata">' );
} );

/**
Expand All @@ -126,7 +126,7 @@ test.describe( 'Front end metadata insertion', () => {
expect( content ).toMatch( /<meta name="parsely-pub-date" content=".*Z">/ );
expect( content ).toContain( '<meta name="parsely-section" content="Uncategorized">' );
expect( content ).toContain( '<meta name="parsely-author" content="admin">' );
expect( content ).not.toContain( '<script type="application/ld+json">' );
expect( content ).not.toContain( '<script type="application/ld+json" class="wp-parsely-metadata">' );
} );

/**
Expand All @@ -145,7 +145,7 @@ test.describe( 'Front end metadata insertion', () => {
expect( content ).toMatch( /<meta name="parsely-pub-date" content=".*Z">/ );
expect( content ).toContain( '<meta name="parsely-section" content="Uncategorized">' );
expect( content ).toContain( '<meta name="parsely-author" content="admin">' );
expect( content ).not.toContain( '<script type="application/ld+json">' );
expect( content ).not.toContain( '<script type="application/ld+json" class="wp-parsely-metadata">' );
} );
} );

Expand Down
Loading