Opened 2 years ago

Closed 11 months ago

#5452 closed change (fixed)

Improve CMS API for local link generation

Reported by: kvas Assignee: rhowell
Priority: Unknown Milestone:
Module: Sitescripts Keywords:
Cc: juliandoucette Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: no Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

https://codereview.adblockplus.org/29979564/

Description (last modified by kvas)

Background

Linkify filter, that is used for generating page links in CMS, breaks display of links in HTML editors and doesn't work well with HTML linters. The problem is that linkify generates the whole <a ...> tag, where it would be better if it generated only the attributes of an <a ...> tag. We would like to have lower level primitives for generating links (available as global functions) that could be used for constructing <a ...> tags in a way that they still look pretty much like <a ...> tags in the template or page source.

What to change

Create two global functions:

  • get_page_url(page[, locale, redirect=False]) that accepts a page path and locale and returns a full url based on website configuration and arguments. If locale is not provided, a link with the locale of the current page should be generated. By default, the function should verify that the page exists in the target locale and should raise an exception if it doesn't. But, if redirect is set to True, it should return the URL in the default locale. If the source has been configured to use relative links, the returned link should be relative.
  • page_has_locale(page, locale) that accepts a page path and locale and returns True if the page exists in that locale and False if it doesn't.

Implementation notes:

  • The base url should be configurable in the website settings via siteurl variable that already exists.
  • Most of the code that generates the links already exists in cms/sources.py:Source.resolve_link.

Change History (7)

comment:1 Changed 17 months ago by rhowell

  • Owner set to rhowell

comment:2 Changed 14 months ago by kvas

  • Description modified (diff)

comment:3 Changed 11 months ago by rhowell

  • Review URL(s) modified (diff)
  • Status changed from new to reviewing

comment:4 Changed 11 months ago by rhowell

  • Description modified (diff)

comment:5 Changed 11 months ago by kvas

  • Description modified (diff)

comment:6 Changed 11 months ago by abpbot

A commit referencing this issue has landed:
Issue 5452 - Improve CMS API for local link generation

comment:7 Changed 11 months ago by rhowell

  • Resolution set to fixed
  • Status changed from reviewing to closed
Note: See TracTickets for help on using tickets.