-
Notifications
You must be signed in to change notification settings - Fork 179
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
createPages according to the translation set in the CMS #47
Comments
@visualcookie This plugin creates copy of each page with url prefixed by language code and each such page has corresponding So if you creates two posts then you got two copies of each page:
I hope, I didn't confuse anything 🧐 |
Well, the thing is, the CMS I'm using already has a translation interface (see in JSON response above) and I don't want people to access a German article by just using the German slug with the locale set to So basically |
@visualcookie You need to delete unwanted pages. For example your can do it in this way:
Hope this helps :) |
Not sure if I can follow you right there. So basically what you are referring to, is to execute the GraphQL query outside of But will |
@visualcookie Something like this but you may store in a Map only page paths, not a whole GraphQL query. // 1. Global scope
const blogPages = new Map()
// ...
//2. Before your createPage call
blogPages.set(`/${a.language}/blog/${a.slug}`, {})
createPage({
//...
context: {
type: 'blog',
}
})
//..
//3. Filter unneccesary pages.
// The point is that you want to keep only pages you store in a Map
// and delete pages that gatsby-plugin-intl creates for your in addition.
exports.onCreatePage = async ({ page, actions }) => {
const isBlogPage = page.context.type === 'blog'
const hasInvalidBlogPath = !blogPages.has(page.path)
//If page is a blog page but has the wrong path
if(isBlogPage && hasUnvalidBlogPath) {
deletePage(page)
}
} |
@angrypie Set this up now and it works. Amazing. |
Hi, I've tried this but I am facing one issue that the hook is injecting e.g. I am creating But my manually created routes to not have any locale information so that they default to the I can't see any solution around this. Would be nice if you've any workaround or hint what I am missing or doing wrong :D Cheers, |
So I've been wondering about this and after reading through a bit of Gatsby's node APIs here's my solution (in case it would be of help to anyone): There are two APIs I will be showing here that are going to make this possible - The first part is in the createPages API. Here, we have to inject a context to the page representing the language of the slug in question. For instance,
Now, as for the second part, it's comparable to the process of post-processing. We deal with the pages we created by checking if they are valid (based on their page) or not. If they aren't valid, we just delete them.
Good luck with your site. |
Hey.
I have
gatsby-plugin-intl
along withgatsby-sourcre-directus7
, which already comes with a translation interface for dynamic content.Now the problem is, that when doing
createPages
for a single blog post, I would end up having the same URLs.Example:
1
has a customslug
in thetranslations
createPages
will be executed/blog/10-tips-to-manage-your-finances
/blog/10-tipps-wie-sie-ihre-finanzen-verwalten
/en/blog/10-tips-to-manage-your-finances
/de/blog/10-tips-to-manage-your-finances
My
gatsby-node.js
file looks as followed:The JSON returned from the above GraphQL request:
I already did try to add
${a.language}
to theurl
, but this resulted in having/en/en/
or/de/de/
. Is there something I'm missing out here?The text was updated successfully, but these errors were encountered: