adobe / aem-spa-project-archetype

Maven Archetype for creating new AEM SPA projects
Apache License 2.0
61 stars 32 forks source link

Sling mapping url shortening support #86

Open cqsapient opened 5 years ago

cqsapient commented 5 years ago

This is a question rather than a feature request/bug.

There is no sling mapping support in the outputted json, is that right? The outputted model.json; if it has any internal link which starts form /content/mysite/en/newpage , will it respect the sling mapping and out put the html with the domain name appended and the url shortened asper the sling mapping? As per my understanding for static page load html parsing happens at run time via sling rewriters transformers which rewrite the links. But since the html is formed on the fly via react, sling rewriters transformers won't come into picture and the outputted json(and the html formed from it) will alwyas have full links starting from content.

Please let me know if my understanding is right.

habansal commented 5 years ago

@cqsapient Yes, indeed! Like you said, since the html is formed on the fly via react, sling rewriters transformers won't come into picture. LinkChecker also uses Sling Request Rewriter Pipeline and only parses content for HTML responses. In case of SPAs, there is no HTML repsonse. So, Linkchecking is also not performed on the pages.

cqsapient commented 5 years ago

Hi @habansal Yes currently I am doing url shortening on publish instances using reverse sling mapping and using resourceresolver.map in backend java sling model which exposes the .model json which is consumed by front end react. So the output json is domain appended and url shortened . I guess this is the most appropriate approach, let me know if you see a cleaner solution.

Now, this approach works fine for new custom components, but I am again facing another issue when using the Content Fragment core component in my SPA. We have enabled CF by creating a corresponding react component and mapped it with the wrapper AEM content fragment component using , which works fine, but I am not able to do url shortening in the CF component as the json is created by core component's code . I know we can extend core component models using Sling delegation patterns,

https://github.com/adobe/aem-core-wcm-components/wiki/Delegation-Pattern-for-Sling-Models

but the doc says we will be able to only use the public methods of the model; and I am not sure which one of these classes

https://github.com/adobe/aem-core-wcm-components/blob/master/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/contentfragment/ContentFragmentImpl.java

https://github.com/adobe/aem-core-wcm-components/blob/master/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/contentfragment/ContentFragmentListImpl.java

https://github.com/adobe/aem-core-wcm-components/blob/master/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/contentfragment/DAMContentFragmentImpl.java

is responsible for rendering the pathfield configured in the CF model(as I want to apply resourceresolver.mapto() in the pathfield's value). Please let me know if it is possible to extend/customize any of these classes in my custom code so that I am able to use resourceresolver.mapto() and hence shorten the url in the json exposed by content fragment.

Will appreciate your help.

Thanks,