Summary
The current implementation in Portal.view.ViewportController stores SEO metadata in a static routeMetadata property directly within the controller. This couples the controller tightly with static data and is not a scalable or maintainable approach.
This task proposes refactoring this logic to follow best practices by separating data, service logic, and view control.
Proposed Architecture
Move Data to JSON File:
- The static SEO metadata will be moved from
ViewportController.mjs to a new JSON file: apps/portal/resources/data/seo.json.
Create a Singleton SEO Service:
- A new singleton service class will be created at
apps/portal/service/Seo.mjs.
- This service will extend
Neo.core.Base.
- In its
initAsync() method, it will use the native fetch() API to load the seo.json file. This simulates fetching data from a real-world API endpoint.
- The fetched data will be cached internally within the service.
- It will expose a public method, such as
getMetadata(route), to provide the SEO data for a given route.
Update ViewportController:
- The
Portal.view.ViewportController will be updated to use the new service.
- It will import the
Seo service.
- The static
routeMetadata property will be removed.
- The
onHashChange method will be modified to:
- Ensure the
Seo service is ready (e.g., await Portal.service.Seo.ready()).
- Call
Portal.service.Seo.getMetadata(route) to retrieve the SEO data.
- Update the document head as it does now.
Acceptance Criteria
- The
routeMetadata static property is removed from Portal.view.ViewportController.
- A new file
apps/portal/resources/data/seo.json exists and contains the SEO metadata.
- A new singleton class
apps/portal/service/Seo.mjs exists and correctly fetches and serves the SEO data.
Portal.view.ViewportController successfully uses the new service to update document head metadata on route changes.
- The application's SEO functionality remains unchanged from a user's perspective.
Summary
The current implementation in
Portal.view.ViewportControllerstores SEO metadata in a staticrouteMetadataproperty directly within the controller. This couples the controller tightly with static data and is not a scalable or maintainable approach.This task proposes refactoring this logic to follow best practices by separating data, service logic, and view control.
Proposed Architecture
Move Data to JSON File:
ViewportController.mjsto a new JSON file:apps/portal/resources/data/seo.json.Create a Singleton SEO Service:
apps/portal/service/Seo.mjs.Neo.core.Base.initAsync()method, it will use the nativefetch()API to load theseo.jsonfile. This simulates fetching data from a real-world API endpoint.getMetadata(route), to provide the SEO data for a given route.Update ViewportController:
Portal.view.ViewportControllerwill be updated to use the new service.Seoservice.routeMetadataproperty will be removed.onHashChangemethod will be modified to:Seoservice is ready (e.g.,await Portal.service.Seo.ready()).Portal.service.Seo.getMetadata(route)to retrieve the SEO data.Acceptance Criteria
routeMetadatastatic property is removed fromPortal.view.ViewportController.apps/portal/resources/data/seo.jsonexists and contains the SEO metadata.apps/portal/service/Seo.mjsexists and correctly fetches and serves the SEO data.Portal.view.ViewportControllersuccessfully uses the new service to update document head metadata on route changes.