Skip to content

Commit

Permalink
Merge pull request #638 from google/fix/506-amp-tag-detection
Browse files Browse the repository at this point in the history
always check the homepage for an existing tag
  • Loading branch information
felixarntz authored Oct 10, 2019
2 parents 1a2b1e7 + b0bdda6 commit 844c96c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions assets/js/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,17 +602,17 @@ export const getExistingTag = async ( module ) => {
// Add a timestamp for cache-busting.
timestamp: Date.now(),
};
let tagFound;

if ( 'secondary' === ampMode ) {
// Always check the homepage regardless of AMP mode.
let tagFound = await scrapeTag( addQueryArgs( homeURL, tagFetchQueryArgs ), module );

if ( ! tagFound && 'secondary' === ampMode ) {
tagFound = await apiFetch( { path: '/wp/v2/posts?per_page=1' } ).then(
// Scrape the first post in AMP mode, if there is one.
( posts ) => posts.slice( 0, 1 ).map( async ( post ) => {
return await scrapeTag( addQueryArgs( post.link, { ...tagFetchQueryArgs, amp: 1 } ), module );
} ).pop()
);
} else {
tagFound = await scrapeTag( addQueryArgs( homeURL, tagFetchQueryArgs ), module );
}

return Promise.resolve( tagFound || null );
Expand Down

0 comments on commit 844c96c

Please sign in to comment.