这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@onurgenes
Copy link
Contributor

@onurgenes onurgenes commented Jan 18, 2022

This is a basic draft of what should be done technically but it is not enough, I guess. In some SEO tools it says "non canonical urls in sitemap" like this help page: https://help.ahrefs.com/en/articles/2652498-non-canonical-page-in-sitemap-error-in-site-audit

For this it needs to be checked if url has a canonical url tag in frontmatter. I couldn't find a good solution for this directly but I am open to suggestions.

This PR is directly related to issue #327

@vercel
Copy link

vercel bot commented Jan 18, 2022

Someone is attempting to deploy a commit to a Personal Account owned by @timlrx on Vercel.

@timlrx first needs to authorize it.

@timlrx
Copy link
Owner

timlrx commented Jan 18, 2022

Thanks for the PR and for pointing out that non-canonical links should not be included in the sitemap. This would require modifying the generate sitemap script but it would be quite a hassle.

You would have to read the markdown files and parse the frontmatter with grey-matter to filter out the ones with canonicalUrl. It would be easier with the planned v2 version of the template which uses contentlayer. You would then simplify read in those js files and filter on them.

My preference is not to implement the canonicalUrl feature for this template but if you are looking to implement it for your blog, I hope the above hints come in useful. If you are in no rush, then perhaps waiting for v2 would be better.

@onurgenes
Copy link
Contributor Author

I have added required fixes to keep it clean but it can be added later on. I will look into it and find a way with names of the files. Maybe adding -canonical at the end of the file and don't include them into the sitemap. What do you think?

@onurgenes onurgenes requested a review from timlrx January 18, 2022 17:13
@timlrx
Copy link
Owner

timlrx commented Jan 19, 2022

I think the best way is to modify the sitemap.xml script such that it reads the frontmatter and determines whether there is a canonical link. My preference is not to do that for this version because of the hassle involved. You can manually exclude those pages in the generation of the sitemap as a workaround.

@miladezzat
Copy link

@onurgenes @timlrx
I think there is a better way to provide the canonical URL

import { useRouter } from "next/router";

const useCanonicalUrl = () => {
  const router = useRouter();

  const pathName = router.pathname === '/' ? '' : router.asPath;

  const url = `${siteUrl}/${router.locale}${pathName}`;
  
  return url;
};

export default useCanonicalUrl;

** Used it **

import useCanonicalUrl from '@/hooks/useCanonicalUrl';

...
const url = useCanonicalUrl();

@timlrx
Copy link
Owner

timlrx commented Jan 29, 2022

@miladezzat the proposed use for the canonicalUrl is to list a 3rd party site as the canonicalUrl, not list the current site's Url as canonical. The later is already automatically added to the SEO headers and is also what your method aims to achieve.

@timlrx
Copy link
Owner

timlrx commented Jan 31, 2022

@onurgenes it should be relatively easy to filter on the frontmatter for the canonicalUrl field now, thanks to a recent pull request. The frontmatter is now parsed in the sitemap.

@onurgenes
Copy link
Contributor Author

Sounds awesome @timlrx! I will look into it this weekend and hopefully release my updated blog too!

@onurgenes
Copy link
Contributor Author

Finally added the latest required check @timlrx. What do you think?

@vercel
Copy link

vercel bot commented Feb 11, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/timlrx/tailwind-nextjs-starter-blog/CXD2pw2C1qWnQc9LckH3kYfotj7j
✅ Preview: https://tailwind-nextjs-starter-blog-git-fork-onurgenes-master-timlrx.vercel.app

@timlrx
Copy link
Owner

timlrx commented Feb 11, 2022

Thanks, once the autoprefixer line has been removed, we should be good to merge it in.

@onurgenes
Copy link
Contributor Author

Auto import... Sorry for that.

Now, it should be fine.

Copy link
Owner

@timlrx timlrx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the new feature!

@timlrx timlrx merged commit b4afda6 into timlrx:master Feb 11, 2022
Meez25 pushed a commit to Meez25/Blog that referenced this pull request Jun 17, 2024
bhiwagade-rahul pushed a commit to bhiwagade-rahul/tailwind-nextjs-starter-blog that referenced this pull request Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants