Skip to content

refactor(blog): do not use static paths file #450

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

Merged
merged 1 commit into from
May 26, 2025
Merged

Conversation

DDonochVA
Copy link
Contributor

@DDonochVA DDonochVA commented May 26, 2025

Summary by CodeRabbit

  • Refactor
    • Updated article language handling to use a more specific language type and locale mappings for improved clarity and consistency.
    • Simplified article existence checks for improved performance and reliability.
    • Standardized the use of locale properties in article sharing and details components.
    • Removed generation of static JSON files for article paths.
  • New Features
    • Added new mappings for converting language codes to locale identifiers.
    • Introduced a new internationalization service to provide active language information.
  • Style
    • Updated component bindings to use locale instead of language for article sharing functionality.

Copy link

coderabbitai bot commented May 26, 2025

Walkthrough

This update refactors how article language and locale are managed and represented across the codebase. It replaces the use of generic language strings with a strongly-typed enum, introduces explicit language-to-locale mappings, removes the generation of language-specific article path JSON assets, and updates component APIs and guards to use the new locale-centric approach. Additionally, a new i18n service is introduced and integrated into the providers.

Changes

File(s) Change Summary
apps/blog/scripts/build-routes.mjs Removed the writeArticlePathsToFile function and its invocation, eliminating JSON generation for article paths by language.
libs/blog-contracts/articles/src/lib/articles.ts Added ArticleLocale type; replaced lang: string with language: DbLang in Article; added mappings between locales, languages, and DbLang.
libs/blog-contracts/articles/src/lib/languages.ts Removed dbLocaleMap and dbLangMap constants previously mapping locales and language codes to DbLang.
libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts Simplified guard to synchronous check of article slug and language; removed HTTP requests and observable pipelines; redirects based on locale.
libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html Changed <al-article-share-icons> input from [language] to [locale] in two places.
libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts Added computed locale property derived from article language using articleLangToLocaleMap.
libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts Renamed language property to locale with type ArticleLocale; updated logic to use locale for URL construction.
libs/blog/i18n/data-access/src/lib/providers.ts Added AlI18nService to provider array alongside AlLocalizeService.
libs/blog/i18n/util/src/index.ts Exported new i18n.service module.
libs/blog/i18n/util/src/lib/i18n.service.ts Added new injectable AlI18nService wrapping TranslocoService with method to get active language as typed enum.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ArticleDetailsComponent
    participant ArticleShareIconsComponent

    User->>ArticleDetailsComponent: Navigates to article
    ArticleDetailsComponent->>ArticleDetailsComponent: Compute locale from article.language using articleLangToLocaleMap
    ArticleDetailsComponent->>ArticleShareIconsComponent: Passes [locale]=locale()
    ArticleShareIconsComponent->>ArticleShareIconsComponent: Uses locale to construct share URLs
Loading

Suggested reviewers

  • mateuszbasinski

Poem

In fields of code where languages flow,
A rabbit hops where locales now grow.
Enums and maps keep things precise,
No more stray strings—just typing nice!
With every hop, a locale appears,
Sharing articles across frontiers.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd50c74 and 25937be.

📒 Files selected for processing (10)
  • apps/blog/scripts/build-routes.mjs (0 hunks)
  • libs/blog-contracts/articles/src/lib/articles.ts (3 hunks)
  • libs/blog-contracts/articles/src/lib/languages.ts (0 hunks)
  • libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts (1 hunks)
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html (2 hunks)
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts (3 hunks)
  • libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts (2 hunks)
  • libs/blog/i18n/data-access/src/lib/providers.ts (2 hunks)
  • libs/blog/i18n/util/src/index.ts (1 hunks)
  • libs/blog/i18n/util/src/lib/i18n.service.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • libs/blog-contracts/articles/src/lib/languages.ts
  • apps/blog/scripts/build-routes.mjs
✅ Files skipped from review due to trivial changes (1)
  • libs/blog/i18n/util/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html
  • libs/blog/i18n/data-access/src/lib/providers.ts
  • libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts
  • libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts
  • libs/blog-contracts/articles/src/lib/articles.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
libs/blog/i18n/util/src/lib/i18n.service.ts (1)
libs/blog-contracts/articles/src/lib/languages.ts (2)
  • Lang (10-10)
  • LangSchema (8-8)
🔇 Additional comments (2)
libs/blog/i18n/util/src/lib/i18n.service.ts (2)

1-5: LGTM: Clean and well-organized imports.

The imports are properly structured with framework dependencies first, followed by third-party libraries, and finally internal modules. The valibot import as * as v is a common pattern that provides clear namespace separation.


7-9: LGTM: Proper service setup with dependency injection.

The service is correctly decorated with @Injectable() and uses Angular's modern inject() function for dependency injection. The readonly modifier on the private field ensures immutability.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@valueadd-robot
Copy link

PR is detected, will deploy to dev environment

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts (1)

67-69: Verify locale mapping consistency.

The hardcoded check for 'pl_PL' should align with the locale values from dbLangToLocaleMap. Consider using a constant or the mapping to avoid hardcoded values.

Consider importing the locale constants to avoid hardcoding:

+ import { dbLangToLocaleMap, DbLang } from '@angular-love/contracts/articles';

  readonly articleUrl = computed(() =>
-   this.locale() === 'pl_PL'
+   this.locale() === dbLangToLocaleMap[DbLang.Polish]
      ? `https://angular.love/pl/${this.slug()}`
      : `https://angular.love/${this.slug()}`,
  );
libs/blog-contracts/articles/src/lib/languages.ts (1)

18-26: Consider adding helper functions for type safety.

While the mapping objects are excellent, consider adding helper functions to ensure type safety and provide better error handling.

Consider adding helper functions for safer usage:

+ export function getLocaleFromDbLang(dbLang: DbLang): string {
+   const locale = dbLangToLocaleMap[dbLang];
+   if (!locale) {
+     throw new Error(`Unsupported DbLang: ${dbLang}`);
+   }
+   return locale;
+ }
+ 
+ export function getLangFromDbLang(dbLang: DbLang): string {
+   const lang = dbLangToLangMap[dbLang];
+   if (!lang) {
+     throw new Error(`Unsupported DbLang: ${dbLang}`);
+   }
+   return lang;
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26f2b1e and cfe2a8f.

📒 Files selected for processing (7)
  • apps/blog/scripts/build-routes.mjs (0 hunks)
  • libs/blog-contracts/articles/src/lib/articles.ts (2 hunks)
  • libs/blog-contracts/articles/src/lib/languages.ts (1 hunks)
  • libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts (1 hunks)
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html (2 hunks)
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts (3 hunks)
  • libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/blog/scripts/build-routes.mjs
🔇 Additional comments (11)
libs/blog-contracts/articles/src/lib/articles.ts (2)

3-3: Excellent type safety improvement!

Adding the DbLang import enables the use of strongly-typed language enums instead of generic strings.


128-128:

✅ Verification successful

Verify all Article interface consumers are updated.

The change from lang: string to language: DbLang is a breaking change that improves type safety but requires all consumers to be updated.

Run the following script to verify all usages of the Article interface are properly updated:


🏁 Script executed:

#!/bin/bash
# Description: Find all usages of Article interface and check for old 'lang' property usage

# Find all TypeScript files that import Article
echo "=== Files importing Article interface ==="
rg -l "import.*Article.*from.*articles" --type ts

# Search for any remaining usage of 'lang' property on Article objects
echo -e "\n=== Potential old 'lang' property usage ==="
rg "\.lang\b" --type ts -A 2 -B 2

# Search for any remaining 'lang:' property definitions
echo -e "\n=== Property definitions using 'lang:' ==="
rg "lang\s*:" --type ts -A 1 -B 1

Length of output: 20110


Verification complete: Article interface consumers updated

No lingering .lang references were found in any TypeScript files importing the Article interface—every consumer now uses language: DbLang. Other occurrences of lang (in middleware tests, database schema, DTOs, etc.) are unrelated to the Article contract and remain valid.

All good to merge.

libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts (1)

62-62: Good API consistency improvement.

Renaming from language to locale aligns with the new locale-centric approach and makes the component API more semantically correct.

libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts (3)

5-5: Good addition of computed import.

Adding computed to support the new reactive locale property.


28-28: Excellent import of mapping utility.

Adding dbLangToLocaleMap enables the type-safe conversion from DbLang enum to locale string.


63-65: Well-implemented reactive locale derivation.

The computed property provides a clean, reactive way to derive the locale from the article's language using the type-safe mapping.

libs/blog-contracts/articles/src/lib/languages.ts (2)

18-21: Excellent reverse mapping for language codes.

The dbLangToLangMap provides a clean reverse lookup from DbLang enum to string language codes, completing the bidirectional mapping capability.


23-26: Perfect locale mapping implementation.

The dbLangToLocaleMap enables type-safe conversion from DbLang enum to locale strings, which is being used effectively in the component layer.

libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts (1)

18-33: LGTM! Excellent simplification from async to sync validation.

The refactoring successfully removes the HTTP dependency and simplifies the guard logic to use in-memory validation. The redirect logic for handling language mismatches is well-implemented.

libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html (2)

35-35: LGTM! Consistent API update for locale handling.

The change from [language]="articleDetails().lang" to [locale]="locale()" is part of the refactoring to use locale-based internationalization. The change is clean and follows the new component API.


86-86: LGTM! Consistent with the previous change.

This maintains consistency with the same property binding change made on line 35, ensuring both instances of the al-article-share-icons component use the new locale-based approach.

@valueadd-robot
Copy link

Deployed to dev environment
Branch: refactor/root-paths
BFF URL: https://27d74a1f-blog-bff-dev.contact-ef8.workers.dev
Deploy URL: https://801a9ce1.angular-love-client.pages.dev
Alias URL: https://refactor-root-paths.angular-love-client.pages.dev

@DDonochVA DDonochVA force-pushed the refactor/root-paths branch from cfe2a8f to fd50c74 Compare May 26, 2025 15:12
@valueadd-robot
Copy link

PR is detected, will deploy to dev environment

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cfe2a8f and fd50c74.

📒 Files selected for processing (10)
  • apps/blog/scripts/build-routes.mjs (0 hunks)
  • libs/blog-contracts/articles/src/lib/articles.ts (3 hunks)
  • libs/blog-contracts/articles/src/lib/languages.ts (0 hunks)
  • libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts (1 hunks)
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html (2 hunks)
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts (3 hunks)
  • libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts (2 hunks)
  • libs/blog/i18n/data-access/src/lib/providers.ts (2 hunks)
  • libs/blog/i18n/util/src/index.ts (1 hunks)
  • libs/blog/i18n/util/src/lib/i18n.service.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • apps/blog/scripts/build-routes.mjs
  • libs/blog-contracts/articles/src/lib/languages.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.html
  • libs/blog/articles/feature-article/src/lib/article-share-icons/article-share-icons.component.ts
  • libs/blog/articles/data-access/src/lib/guards/article-exists.guard.ts
  • libs/blog/articles/feature-article/src/lib/article-details/article-details.component.ts
  • libs/blog-contracts/articles/src/lib/articles.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
libs/blog/i18n/util/src/lib/i18n.service.ts (1)
libs/blog-contracts/articles/src/lib/languages.ts (1)
  • Lang (10-10)
🔇 Additional comments (3)
libs/blog/i18n/util/src/index.ts (1)

3-3: LGTM! Proper barrel file export.

The export addition follows standard barrel file patterns and makes the new service publicly accessible.

libs/blog/i18n/data-access/src/lib/providers.ts (2)

7-7: LGTM! Correct import addition.

The import statement properly includes the new AlI18nService alongside the existing service.


34-34: LGTM! Proper DI registration.

The service is correctly added to the providers array for dependency injection.

@valueadd-robot
Copy link

Deployed to dev environment
Branch: refactor/root-paths
BFF URL: https://9f90c863-blog-bff-dev.contact-ef8.workers.dev
Deploy URL: https://468da3d9.angular-love-client.pages.dev
Alias URL: https://refactor-root-paths.angular-love-client.pages.dev

@DDonochVA DDonochVA force-pushed the refactor/root-paths branch from fd50c74 to 25937be Compare May 26, 2025 15:20
@valueadd-robot
Copy link

PR is detected, will deploy to dev environment

@valueadd-robot
Copy link

Deployed to dev environment
Branch: refactor/root-paths
BFF URL: https://1b869684-blog-bff-dev.contact-ef8.workers.dev
Deploy URL: https://b84cb5eb.angular-love-client.pages.dev
Alias URL: https://refactor-root-paths.angular-love-client.pages.dev

@DDonochVA DDonochVA merged commit 885edf3 into main May 26, 2025
2 checks passed
@DDonochVA DDonochVA deleted the refactor/root-paths branch May 26, 2025 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants