Skip to content
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

fix: tup-694 abs URLs to same domain should be rel #811

Merged

Conversation

wesleyboar
Copy link
Member

@wesleyboar wesleyboar commented Mar 5, 2024

Overview

Make setTargetForExternalLinks also change link URL to relative if it is absolute yet on same host.

Related

Changes

  • added feature to script setTargetForExternalLinks

Testing

Set up:

  1. Check out branch fix/tup-694-absolute-urls-to-same-domain-should-be-relative.

  2. Update local CMS with new code (e.g. rebuild or "collectstatic").

    Commands
    • either make stop && make build && make start
    • or docker-compose -f ./docker-compose.dev.yml up --detach && docker exec -it core_cms sh -c "python manage.py collectstatic --no-input"
  3. Open CMS e.g. http://localhost:8000/.

Test fix:

  1. Create/Identify a link that both is to a different page on the same host and uses an absolute URL.
  2. Verify markup of link has href with absolute path.
  3. Refresh page (to run JavaScript on new markup). Verify markup of link has href with a relative path.
  4. Click link. Verify page still opens.

UI

4 5 6 7
4 create link 5 markup has absolute url 6 markup has relative link 7 new link opens

@wesleyboar wesleyboar marked this pull request as ready for review March 5, 2024 20:31
Comment on lines -11 to +13
const links = document.getElementsByTagName('a');
const links = document.querySelectorAll('body > :is(header, main, footer) a');
Copy link
Member Author

Choose a reason for hiding this comment

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

Why? So that CMS Admin UI toolbar links are not affected. I noticed the placeholder snippet version of this PR was breaking the CMS Admin UI toolbar.

@@ -18,8 +20,10 @@ export default function findLinksAndSetTargets() {
}

const isMailto = ( link.href.indexOf('mailto:') === 0 );
const isAbsolute = (link.href.indexOf('http') === 0);
const isSameHost = link.host === baseDocHost || link.host === baseDocHostWithSubdomain
Copy link
Member Author

Choose a reason for hiding this comment

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

New name? Yes. Renamed in noop polish PR #810.

Copy link
Collaborator

@R-Tomas-Gonzalez R-Tomas-Gonzalez left a comment

Choose a reason for hiding this comment

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

This looks good and worked for me.

@wesleyboar wesleyboar merged commit 5ae95ab into main Mar 6, 2024
@wesleyboar wesleyboar deleted the fix/tup-694-absolute-urls-to-same-domain-should-be-relative branch March 6, 2024 19:31
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