fix: multilingual URL rendering with uglyURLs#14689
fix: multilingual URL rendering with uglyURLs#14689xingzihai wants to merge 1 commit intogohugoio:masterfrom
Conversation
Fixes gohugoio#14576 When using multilingual website with defaultContentLanguageInSubdir=true and uglyURLs=true, Hugo was incorrectly creating a redirect at the default language home page that would overwrite the actual content. The issue was in renderDefaultSiteRedirect where the code was creating redirects for all directory levels, including the directory that contains the index file. With uglyURLs enabled, the homeLink ends with an index file (e.g., '/en/index.html'), and the redirect path would resolve to the same file, overwriting the home page. This fix adds a check to skip creating redirects for the directory that contains the index file when uglyURLs is enabled. Changes: - hugolib/site_render.go: Add skipCount logic to skip redirect creation for directories containing index files - hugolib/sitesmatrix/sitematrix_integration_test.go: Add test case TestSitesMatrixUglyURLsDefaultContentLanguageInSubdir to verify the fix Tested with: - Manual test site with multilingual (en, zh) + defaultContentLanguageInSubdir=true + uglyURLs=true - All home pages correctly generated with actual content - Root redirect correctly points to default language home page
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
|
|
This PR does not address this comment: If we decide on a partial fix to close #14576, we must create a new issue to cover the multihost scenario. I also think that we may want to address #13346 concurrently. |
|
Hi, renderDefaultSiteRedirect skips creating a redirect for the directory containing the home output whenever the homeLink filename starts with of.BaseName + ".". Alias publishing always writes redirects to index.html for directory aliases, so this skip can incorrectly suppress redirects when the home page is written to a different filename (e.g., index.b via custom HTML suffix), where no overwrite/collision would occur. Severity: remediation recommended | Category: correctness How to fix: Skip only on real collision Agent prompt to fix - you can give this to your LLM of choice:
Found by Qodo code review. FYI, Qodo is free for open-source. |
This PR fixes multilingual URL rendering when uglyURLs is enabled.\n\n## Changes\n- Fixed URL rendering to properly handle multilingual sites with uglyURLs\n\nFixes #14576