From 9490884b5ab196e0e811d064d1d1304b11b080cd Mon Sep 17 00:00:00 2001 From: MDLeom <2809763-curben@users.noreply.gitlab.com> Date: Wed, 19 Aug 2020 03:29:17 +0000 Subject: [PATCH] feat(helper): titleCase - simpler version of https://github.com/rvagg/titlecase * no exceptions --- themes/chameleon/layout/_partial/head.ejs | 2 +- themes/chameleon/layout/_partial/post/tag.ejs | 2 +- themes/chameleon/layout/index.ejs | 2 +- themes/chameleon/layout/tag-index.ejs | 2 +- themes/chameleon/scripts/titleCase.js | 13 +++++++++++++ 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 themes/chameleon/scripts/titleCase.js diff --git a/themes/chameleon/layout/_partial/head.ejs b/themes/chameleon/layout/_partial/head.ejs index 87dbf61..93e9af5 100644 --- a/themes/chameleon/layout/_partial/head.ejs +++ b/themes/chameleon/layout/_partial/head.ejs @@ -4,7 +4,7 @@ let title = page.title if (is_archive()) { - title = titlecase(config.archive_dir) + title = titleCase(config.archive_dir) if (is_month()) { title += ': ' + page.year + '/' + page.month diff --git a/themes/chameleon/layout/_partial/post/tag.ejs b/themes/chameleon/layout/_partial/post/tag.ejs index 9937c99..994a87f 100644 --- a/themes/chameleon/layout/_partial/post/tag.ejs +++ b/themes/chameleon/layout/_partial/post/tag.ejs @@ -2,6 +2,6 @@ <%- list_tags(post.tags, { show_count: false, class: 'article-tag', - transform: titlecase + transform: titleCase }) %> <% } %> diff --git a/themes/chameleon/layout/index.ejs b/themes/chameleon/layout/index.ejs index 86a5277..830fc33 100644 --- a/themes/chameleon/layout/index.ejs +++ b/themes/chameleon/layout/index.ejs @@ -10,6 +10,6 @@ <%- list_tags({ amount: 0, class: 'index', - transform: titlecase + transform: titleCase }) %> diff --git a/themes/chameleon/layout/tag-index.ejs b/themes/chameleon/layout/tag-index.ejs index 9265961..757e07c 100644 --- a/themes/chameleon/layout/tag-index.ejs +++ b/themes/chameleon/layout/tag-index.ejs @@ -5,6 +5,6 @@ <%- list_tags({ amount: 0, class: 'index', - transform: titlecase + transform: titleCase }) %> diff --git a/themes/chameleon/scripts/titleCase.js b/themes/chameleon/scripts/titleCase.js new file mode 100644 index 0000000..7540823 --- /dev/null +++ b/themes/chameleon/scripts/titleCase.js @@ -0,0 +1,13 @@ +'use strict' +/* global hexo */ + +/* +* Simpler version of titlecase() https://github.com/rvagg/titlecase +* Does not ignore words with a dot +*/ + +hexo.extend.helper.register('titleCase', (str) => { + return str.replace(/[\w]+[^\s-]*/g, (match) => { + return match.charAt(0).toUpperCase() + match.substr(1) + }) +})