Skip to content
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

[docs-infra] Improve product mapping #37729

Merged
merged 5 commits into from
Jun 28, 2023

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Jun 26, 2023

This is a continuation of #37593, to be able to segment the traffic on GA4 between products, it fixes bugs at the same time.

  • Rename product -> productId to make it easier to navigate the codebase, better be clear as well.
  • Rely on the productId stored in Algolia for the matching, rather than trying to re-compute the value from the pathname, this is wrong.
  • Cleanup getProductInfoFromUrl() to be simpler a step toward the future

The next steps would be:

  • Moving the productId logic out of docs-infra to be inside each docs. getProductInfoFromUrl() is hybrid, it feels like a leaky abstraction
  • Have the markdown pages productId override the logic of getProductInfoFromUrl(). There are cases when the URL structure is not straightforward.
  • useDemoData() has its own product id logic, this duplication is wrong. it should rely on the PageContext, no reasons to be different.

@oliviertassinari oliviertassinari added the scope: docs-infra Specific to the docs-infra product label Jun 26, 2023
oliviertassinari and others added 2 commits June 26, 2023 17:10
Co-authored-by: Lukas <llukas.tyla@gmail.com>
Signed-off-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Comment on lines -6 to -20
{
pathname: '/getting-started',
icon: standardNavIcons.DescriptionIcon,
children: [
{ pathname: '/getting-started/installation' },
{ pathname: '/getting-started/usage' },
{ pathname: '/getting-started/example-projects' },
{ pathname: '/getting-started/templates' },
{ pathname: '/getting-started/learn', title: 'Learning resources' },
{ pathname: '/getting-started/faq', title: 'FAQs' },
{ pathname: '/getting-started/supported-components' },
{ pathname: '/getting-started/supported-platforms' },
{ pathname: '/getting-started/support' },
],
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Legacy, dead code

Comment on lines +42 to 50
if (firstFolder === 'x') {
productCategoryId = 'x';
productId = `x-${asPathWithoutLang.replace('/x/react-', '').replace(/\/.*/, '')}`;
}

if (asPathWithoutLang === '/versions/') {
productId = null;
// No match, give up on it.
if (productId === 'x-') {
productId = 'null';
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

With the changes in this PR, we could in theory move this logic to http://github.com/mui/mui-x. To complement #9451. But one step at a time. This is made possible by no longer relying on getProductInfoFromUrl to label the Algolia search results.

@@ -85,7 +85,7 @@ const products = [
];

export default function MuiProductSelector() {
const { productId } = React.useContext(PageContext);
const pageContext = React.useContext(PageContext);
Copy link
Member Author

Choose a reason for hiding this comment

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

So much easier for large scale code refactoring.

Comment on lines +343 to +346
// Extra
'productId',
'productCategoryId',
],
Copy link
Member Author

Choose a reason for hiding this comment

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

In Algolia Crawler, we get these values like this:

{
  productId: $('meta[name="mui:productId"]').attr("content"),
  productCategoryId: $('meta[name="mui:productCategoryId"]').attr("content"),
}

@Janpot
Copy link
Member

Janpot commented Jun 28, 2023

May want to incorporate the edge cases in https://github.com/mui/material-ui/pull/37721/files and close that one

@oliviertassinari
Copy link
Member Author

@Janpot Ah yes, great. I have updated this PR.

@oliviertassinari oliviertassinari merged commit caf7207 into mui:master Jun 28, 2023
19 checks passed
@oliviertassinari oliviertassinari deleted the improve-product-mapping branch June 28, 2023 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work scope: docs-infra Specific to the docs-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants