-
Notifications
You must be signed in to change notification settings - Fork 8
Extract hard-coded routes into centralized constants (resolves #747) #1127
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
Open
BenjaminMichaelis
wants to merge
4
commits into
main
Choose a base branch
from
benjaminmichaelis/extract-content-page-routes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e1ced4d
Extract hard-coded routes into centralized constants (issue #747)
BenjaminMichaelis a414c0b
Fix bugs found in critic review of route constants
BenjaminMichaelis cbe21bb
Make FrozenSet comparer explicit for NonContentRoutes
BenjaminMichaelis 846d84c
Address PR review: stable v-for key and normalize /announcements casing
BenjaminMichaelis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using System.Collections.Frozen; | ||
| using DotnetSitemapGenerator; | ||
|
|
||
| namespace EssentialCSharp.Web.Constants; | ||
|
|
||
| /// <summary> | ||
| /// Centralized definition of application routes and their metadata. | ||
| /// This is the single source of truth for static page route paths. | ||
| /// Update these whenever a static page is added, removed, or renamed. | ||
| /// </summary> | ||
| public static class RouteConstants | ||
| { | ||
| /// <summary> | ||
| /// Static page routes that are not content pages (e.g., informational, utility pages). | ||
| /// Content pages are dynamically discovered from sitemap.json. | ||
| /// </summary> | ||
| public static class StaticPages | ||
| { | ||
| public const string Home = "/home"; | ||
| public const string About = "/about"; | ||
| public const string Guidelines = "/guidelines"; | ||
| public const string Announcements = "/announcements"; | ||
| public const string TermsOfService = "/termsofservice"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Immutable set of non-content route paths. Use to determine if a requested path | ||
| /// is a static page (non-content) rather than a content page (from sitemap). | ||
| /// </summary> | ||
| public static readonly FrozenSet<string> NonContentRoutes = new HashSet<string>(StringComparer.OrdinalIgnoreCase) | ||
| { | ||
| StaticPages.Home, | ||
| StaticPages.About, | ||
| StaticPages.Guidelines, | ||
| StaticPages.Announcements, | ||
| StaticPages.TermsOfService | ||
| }.ToFrozenSet(StringComparer.OrdinalIgnoreCase); | ||
|
|
||
| /// <summary> | ||
| /// SEO metadata for static routes used in sitemap.xml generation. | ||
| /// </summary> | ||
| public static class SeoMetadata | ||
| { | ||
| /// <summary> | ||
| /// Immutable map of route paths to (ChangeFrequency, Priority) tuples. | ||
| /// Keys include the leading slash (e.g. "/home") to match how ASP.NET Core | ||
| /// exposes routes. Priority is 0.0–1.0; 0.5 is the sitemap default. | ||
| /// </summary> | ||
| public static readonly FrozenDictionary<string, (ChangeFrequency Frequency, decimal Priority)> RouteConfig = | ||
| new Dictionary<string, (ChangeFrequency, decimal)>(StringComparer.OrdinalIgnoreCase) | ||
| { | ||
| { StaticPages.Home, (ChangeFrequency.Monthly, 0.5m) }, | ||
| { StaticPages.About, (ChangeFrequency.Monthly, 0.5m) }, | ||
| { StaticPages.Guidelines, (ChangeFrequency.Monthly, 0.9m) }, | ||
| { StaticPages.Announcements, (ChangeFrequency.Monthly, 0.5m) }, | ||
| { StaticPages.TermsOfService,(ChangeFrequency.Yearly, 0.2m) } | ||
| }.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * Centralized route constants for the frontend. | ||
| * Mirrors the backend RouteConstants to ensure consistency across frontend and backend. | ||
| * Update these whenever routes are added, removed, or changed. | ||
| */ | ||
|
|
||
| export const ROUTES = { | ||
| HOME: '/home', | ||
| ABOUT: '/about', | ||
| GUIDELINES: '/guidelines', | ||
| ANNOUNCEMENTS: '/announcements', | ||
| TERMS_OF_SERVICE: '/termsofservice' | ||
| }; | ||
|
|
||
| /** | ||
| * Array of non-content route paths. | ||
| * Use with Array.includes() to determine if a path is a static page vs. a content page. | ||
| */ | ||
| export const NON_CONTENT_ROUTES = [ | ||
| ROUTES.HOME, | ||
| ROUTES.ABOUT, | ||
| ROUTES.GUIDELINES, | ||
| ROUTES.ANNOUNCEMENTS, | ||
| ROUTES.TERMS_OF_SERVICE | ||
| ]; | ||
|
|
||
| /** | ||
| * Navigation link definitions for the sidebar. | ||
| * Each link includes href, label, icon class, and active path matching patterns. | ||
| * Note: ROUTES.TERMS_OF_SERVICE is intentionally excluded from this list — | ||
| * it is a legal page linked in the footer, not a primary navigation destination. | ||
| */ | ||
| export const NAVIGATION_LINKS = [ | ||
| { | ||
| href: ROUTES.HOME, | ||
| label: 'Home', | ||
| iconClass: 'fas fa-home me-2', | ||
| activePaths: ['/', ROUTES.HOME], | ||
| key: 'home' | ||
| }, | ||
| { | ||
| href: ROUTES.ABOUT, | ||
| label: 'About', | ||
| iconClass: 'fas fa-book me-2', | ||
| activePaths: [ROUTES.ABOUT], | ||
| key: 'about' | ||
| }, | ||
| { | ||
| href: ROUTES.GUIDELINES, | ||
| label: 'Guidelines', | ||
| iconClass: 'fas fa-code me-2', | ||
| activePaths: [ROUTES.GUIDELINES], | ||
| key: 'guidelines' | ||
| }, | ||
| { | ||
| href: ROUTES.ANNOUNCEMENTS, | ||
| label: 'Announcements', | ||
| iconClass: 'fas fa-bullhorn me-2', | ||
| activePaths: [ROUTES.ANNOUNCEMENTS], | ||
| key: 'announcements' | ||
|
BenjaminMichaelis marked this conversation as resolved.
|
||
| } | ||
| ]; | ||
|
|
||
| /** | ||
| * Determines if the given path is a content page (from sitemap) | ||
| * versus a static page (non-content). | ||
| * @param {string} path - The path to check | ||
| * @returns {boolean} - True if path is a content page, false if static page | ||
| */ | ||
| export function isContentPagePath(path) { | ||
| const normalizedPath = path.toLowerCase(); | ||
| return !NON_CONTENT_ROUTES.some(route => | ||
| normalizedPath === route.toLowerCase() || | ||
| normalizedPath.startsWith(route.toLowerCase() + '/') | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.