Commits: 2
Implement a smarter title capitalization macro
Mostly to fix ERP capitalization, deal with abbreviations in general and other kinks.
index 8bdc03d..0b0a020 100644
--- a/templates/components.html
+++ b/templates/components.html
@@ -133,3 +133,64 @@
= {\{ components::natural_list(items=feature.pages | map (attribute="title")) \}}
= </p>
={\% endmacro feature_heading %}
+
+
+{# Roughly follow the Associated Press style for titles capitalization #}
+{\% macro title (text) %}
+ {\% set ignored_words = [
+ "a",
+ "and",
+ "as",
+ "at",
+ "but",
+ "by",
+ "for",
+ "from",
+ "if",
+ "in",
+ "into",
+ "like",
+ "near",
+ "nor",
+ "of",
+ "off ",
+ "on",
+ "once",
+ "onto",
+ "or",
+ "so",
+ "than",
+ "that",
+ "to",
+ "upon",
+ "when",
+ "with",
+ "yet"
+ ] %}
+
+ {\% for token in text | split(pat=" ") %}
+ {\% set word = token
+ | replace (from=",", to="")
+ | replace (from=".", to="")
+ | replace (from=":", to="")
+ | replace (from=";", to="")
+ | replace (from="?", to="")
+ | replace (from="!", to="")
+ | replace (from="(", to="")
+ | replace (from=")", to="")
+ | replace (from='"', to="")
+ | replace (from="'", to="")
+ %}
+ {# Never capitalize words that contain any uppercase letter, number or special characters #}
+ {\% if word is matching ("[A-Z0-9@#$\^&\*_\+\`><]") %}
+ {\{ token \}}
+ {# Otherwise always capitalize first and last word #}
+ {\% elif loop.first or loop.last %}
+ {\{ token | title \}}
+ {\% elif ignored_words is containing (word) %}
+ {\{ token \}}
+ {\% else %}
+ {\{ token | title \}}
+ {\% endif %}
+ {\% endfor %}
+{\% endmacro title %}index f87f027..6b31327 100644
--- a/templates/features/single.html
+++ b/templates/features/single.html
@@ -32,7 +32,7 @@
= {\% endif %}
= {\% endfor %}
= {\% if solutions %}
- <h3>{\{ category.name | title \}}</h3>
+ <h3>{\{ components::title(text=category.name) \}}</h3>
= <section class="card-grid">
= {\% for solution in solutions %}
= {\{ components::solution_card(solution=solution) \}}index 1deb8ac..e33e7da 100644
--- a/templates/solutions.html
+++ b/templates/solutions.html
@@ -9,7 +9,7 @@
=
= {\% set taxonomy = get_taxonomy(kind="solution_categories") %}
= {\% for category in taxonomy.items %}
- <h2>{\{ category.name | title \}}</h2>
+ <h2>{\{ components::title(text=category.name) \}}</h2>
=
= <section class="card-grid">
= {\% for solution in category.pages %}Fix indentation in components.html
index 0b0a020..37f6807 100644
--- a/templates/components.html
+++ b/templates/components.html
@@ -1,29 +1,29 @@
={# These are reusable components (macros) #}
=
={\% macro feature_bullet(feature, link=true) %}
-{\% set feature_slug = feature | slugify %}
-{\% set feature_moji = "black star" %}
-
-{\% set feature_path = "solutions/features/" ~ feature_slug ~ ".md" %}
-{# TODO: Consider if a feature page should be required
-
- As it is now, they can be skipped. But maybe we want to
- ensure that every feature is defined? At the very least it
- would prevent typos.
-#}
-{\% set feature_data = load_data (path=feature_path, required=false) %}
-{\% if feature_data %}
- {\% set feature_page = get_page(path=feature_path) %}
- {\% if feature_page.extra.moji %}
- {\% set feature_moji = feature_page.extra.moji %}
+ {\% set feature_slug = feature | slugify %}
+ {\% set feature_moji = "black star" %}
+
+ {\% set feature_path = "solutions/features/" ~ feature_slug ~ ".md" %}
+ {# TODO: Consider if a feature page should be required
+
+ As it is now, they can be skipped. But maybe we want to
+ ensure that every feature is defined? At the very least it
+ would prevent typos.
+ #}
+ {\% set feature_data = load_data (path=feature_path, required=false) %}
+ {\% if feature_data %}
+ {\% set feature_page = get_page(path=feature_path) %}
+ {\% if feature_page.extra.moji %}
+ {\% set feature_moji = feature_page.extra.moji %}
+ {\% endif %}
= {\% endif %}
-{\% endif %}
=
= <li class="om om-{\{ feature_moji | slugify \}}">
= {\% if link %}
= <a href="{\{ get_url(path="/features/" ~ feature_slug) \}}">
= {\% endif %}
- {\{ feature \}}
+ {\{ feature \}}
= {\% if link %}
= </a>
= {\% endif %}