mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Allow text substitutions when generating slugs
The `slugify()` function used by Pelican is in general very good at coming up with something both readable and URL-safe. However, there are a few specific cases where it causes conflicts. One that I've run into is using the strings `C++` and `C` as tags, both of which transform to the slug `c`. This commit adds an optional `SLUG_SUBSTITUTIONS` setting which is a list of 2-tuples of substitutions to be carried out case-insensitively just prior to stripping out non-alphanumeric characters. This allows cases like `C++` to be transformed to `CPP` or similar. This can also improve the readability of slugs.
This commit is contained in:
parent
7ec4d5faa2
commit
39518e15ef
6 changed files with 28 additions and 8 deletions
|
|
@ -94,6 +94,17 @@ class TestUtils(LoggedTestCase):
|
|||
for value, expected in samples:
|
||||
self.assertEqual(utils.slugify(value), expected)
|
||||
|
||||
def test_slugify_substitute(self):
|
||||
|
||||
samples = (('C++ is based on C', 'cpp-is-based-on-c'),
|
||||
('C+++ test C+ test', 'cpp-test-c-test'),
|
||||
('c++, c#, C#, C++', 'cpp-c-sharp-c-sharp-cpp'),
|
||||
('c++-streams', 'cpp-streams'),)
|
||||
|
||||
subs = (('C++', 'CPP'), ('C#', 'C-SHARP'))
|
||||
for value, expected in samples:
|
||||
self.assertEqual(utils.slugify(value, subs), expected)
|
||||
|
||||
def test_get_relative_path(self):
|
||||
|
||||
samples = ((os.path.join('test', 'test.html'), os.pardir),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue