Opened 3 years ago

Last modified 15 months ago

#5452 closed change

Improve CMS API for local link generation — at Version 5

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):

Description (last modified by kvas)


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/

Change History (5)

comment:1 Changed 21 months ago by rhowell

  • Owner set to rhowell

comment:2 Changed 18 months ago by kvas

  • Description modified (diff)

comment:3 Changed 15 months ago by rhowell

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

comment:4 Changed 15 months ago by rhowell

  • Description modified (diff)

comment:5 Changed 15 months ago by kvas

  • Description modified (diff)
Note: See TracTickets for help on using tickets.