Thank you for your interest and detailed explanation.
We do not have a special reason to use the .html extension, but the link structure has been like this for 4 years. It would not be healthy to update the link structure as âpost nameâ as stated in the document, because we have more than 20,000 articles. So the only thing we can do is remove the â.htmlâ at the end of the link.
But you will appreciate that making such a link structure change directly on an authoritative site like this can be risky for Google indexes.
Thereâs been some more progress on the issue and the fix itâs fairly straight. Would you be open to contribute with the fix yourself?
We would love and welcome any contribution! We have a fairly easy to start contribution guide. Thereâs nothing else like fixing an issue on an open-source software.
Let me know if thereâs more that I can do in here.
Have a great one!
I tried this in mars-theme index.js file. It didnât work. I also tried in console but nothing changed. I can reach the same post multiple times with different browser tabs but when I press refresh button, it gives me 404 error.
Did you tried this action? Maybe Iâm missing something.
I think the issue is because we are using the init function, which doesnât guarantee that the libraries from other packages have been initialized. In this case the handlers from wp-source.
In Frontity, the packages are initialized in the order they are defined in the frontity.settings.js file. In the case of the default mars-theme, the theme is before the wp-source package. This means that when we call the init function of the theme, the handlers donât exist yet.
I guess I didnât understand exactly where to use these actions. When I check âfrontity.libraries.source.handlersâ value at the console, I donât see handlers ending with â.htmlâ.
For mars-theme, can you tell me where I should place this action youâve sent?
For mars-theme, can you tell me where I should place this action youâve sent?
Sure! In the case of the default mars-theme I think you could edit the index.js file. This could be it:
import Theme from "./components";
import image from "@frontity/html2react/processors/image";
import iframe from "@frontity/html2react/processors/iframe";
import link from "@frontity/html2react/processors/link";
const marsTheme = {
name: "@frontity/mars-theme",
roots: {
/**
* In Frontity, any package can add React components to the site.
* We use roots for that, scoped to the `theme` namespace.
*/
theme: Theme,
},
state: {
/**
* State is where the packages store their default settings and other
* relevant state. It is scoped to the `theme` namespace.
*/
theme: {
autoPrefetch: "in-view",
menu: [],
isMobileMenuOpen: false,
featured: {
showOnList: false,
showOnPost: false,
},
},
},
/**
* Actions are functions that modify the state or deal with other parts of
* Frontity like libraries.
*/
actions: {
theme: {
toggleMobileMenu: ({ state }) => {
state.theme.isMobileMenuOpen = !state.theme.isMobileMenuOpen;
},
closeMobileMenu: ({ state }) => {
state.theme.isMobileMenuOpen = false;
},
beforeSSR: ({ libraries }) => {
libraries.source.handlers.map((handler) => {
console.log(handler.pattern);
handler.pattern += "(\\.html)?";
return handler;
});
},
},
},
libraries: {
html2react: {
/**
* Add a processor to `html2react` so it processes the `<img>` tags
* and internal link inside the content HTML.
* You can add your own processors too.
*/
processors: [image, iframe, link],
},
},
};
export default marsTheme;
Oh, I see. I just checked that the post was loading correctly in SSR.
With the second option I suggested, using the init function instead of beforeSSR, but moving the wp-source package before the mars-theme package in the frontity.settings.js file, it seems to appear also in the console. Did that work for you?
Youâre right. Iâve noticed that it only works for the latest post. The older ones donât work in SSR with these solutions. Iâve written what I found in the issue to keep researching the issue there.
It wouldnât work as it is because it would require that our postTypeHandler checks if there is a params.id and use that instead of the params.slug to retrieve the content from the REST API. But I think a change like that would make sense. It is also explained in the video.