Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-8378

Configurable way to end links with slash

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Neutral Neutral
    • None
    • 6.2.17
    • core
    • Yes
    • Yes

      Frequently we are getting requests about how to generate links with a slash at the end rather than dot html or nothing at all. We need a configurable way to tell the system (LinkUtil) to generate links with a slash at the end. Mostly for SEO purposes.

      The new configuration might make sense here /server/rendering/linkManagement/transformers.

      endLinksWithSlash = true
      

      Probably it would need to override any value that is configured here /server@defaultExtension

      Another option would be to allow '/' to be an acceptable value for /server@defaultExtension

      Notes
      One of the issues we face is there is no easy way to override LinkUtil. It's not in the server config nor is it defined in a module descriptor.

      The system is already capable of handling the ending slash. All of these links work:

      Workaround
      First, you will need remove the html value of /server/defaultExtension property (but this leaves the "." at the end of generated links).
      So second, to be able to use just "/" as default extension you have to modify info.magnolia.cms.beans.config.URI2RepositoryMapping class and its getURI method. Like this:

          public String getURI(Link uuidLink){
              String uri = uuidLink.getHandle();
              if (StringUtils.isNotEmpty(this.handlePrefix)) {
                  uri = StringUtils.removeStart(uri, this.handlePrefix);
              }
              if (StringUtils.isNotEmpty(this.URIPrefix)) {
                  uri = this.URIPrefix + "/" + uri;
              }
      
              String nodeDataName = uuidLink.getNodeDataName();
              String fileName = uuidLink.getFileName();
              String extension = uuidLink.getExtension();
      
              if(StringUtils.isNotEmpty(nodeDataName)){
                  uri += "/" + nodeDataName;
              }
              if(StringUtils.isNotEmpty(fileName)){
                  uri += "/" + fileName;
              }
              if(StringUtils.isNotEmpty(uri) && StringUtils.isNotEmpty(extension) && !StringUtils.endsWith(uri, "/")){
      -           uri += "." + extension ;
      +           uri += extension ;
              }
      
              return cleanHandle(uri);
          }
      

      With that change in magnolia-core you will no longer get hardcoded "." before extension and (also google sitemap module) will use this new format with default configuration.

        Acceptance criteria

              Unassigned Unassigned
              rgange Richard Gange
              Nucleus
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:

                  Task DoD