Skip to content
New issue

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

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

Already on GitHub? # to your account

Origin with empty string is causing canonical meta not be appended on AMP pages #181

Closed
jongeyer opened this issue Sep 29, 2020 · 1 comment

Comments

@jongeyer
Copy link

jongeyer commented Sep 29, 2020

I'm using the amp-module on a project and deploying with Vercel. In this case I know the production url, but I need to also test in preview deployments with dynamically generated base url's. I expect that the origin as empty string ('') should make this work:

...
amp: {
  origin: '',
  mode: 'hybrid'
},
...

Expected result:

  • "canonical" link added on AMP pages
  • "amphtml" link added on non-AMP pages

Actual result:

  • "canonical" link NOT added on AMP pages
  • "amphtml" link added on non-AMP pages

The logic for this is in plugin.js:

if (origin && !head.link.find(l => l.rel === 'canonical' || l.hid === 'canonical')) {

Why is this condition checking if origin is truthy?
The same condition does not apply for appending the amphtml meta.

@jongeyer jongeyer changed the title Origin with empty string is causing canonical links not be appended Origin with empty string is causing canonical meta not be appended on AMP pages Sep 29, 2020
@jongeyer
Copy link
Author

jongeyer commented Sep 30, 2020

My solution/workaround (specific to vercel):

...
amp: {
  origin: process.env.BASE_URL || `//${process.env.VERCEL_URL}`,
  mode: 'hybrid'
},
...

BASE_URL is localhost for dev environment, and production url on prod environment

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants