mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-10 21:01:41 +00:00
Include flag context in excerpt (#294)
* Added avoid flag text to meta descriptions * Moved meta description logic to a shortcode * Fixing nunjucks syntax error in base template head Co-authored-by: Oscar <ovlb@users.noreply.github.com>
This commit is contained in:
43
11ty/shortcodes/__tests__/metaDescriptionWithFlag.spec.js
Normal file
43
11ty/shortcodes/__tests__/metaDescriptionWithFlag.spec.js
Normal file
@ -0,0 +1,43 @@
|
||||
import test from 'ava';
|
||||
|
||||
import metaDescriptionWithFlag from '../metaDescriptionWithFlag';
|
||||
|
||||
test('renders with flag.level = avoid and flag.text present', (t) => {
|
||||
const flag = {
|
||||
level: 'avoid',
|
||||
text: 'ableist slur'
|
||||
};
|
||||
const preview = 'here is some preview text';
|
||||
|
||||
t.is(
|
||||
metaDescriptionWithFlag(preview, flag),
|
||||
'Avoid: ableist slur. Here is some preview text'
|
||||
);
|
||||
});
|
||||
|
||||
test('renders with flag.level = avoid and no flag.text', (t) => {
|
||||
const flag = {
|
||||
level: 'avoid'
|
||||
};
|
||||
const preview = 'here is some preview text';
|
||||
|
||||
t.is(
|
||||
metaDescriptionWithFlag(preview, flag),
|
||||
'Avoid: here is some preview text'
|
||||
);
|
||||
});
|
||||
|
||||
test('renders with flag.level != avoid', (t) => {
|
||||
const flag = {
|
||||
level: 'warning'
|
||||
};
|
||||
const preview = 'here is some preview text';
|
||||
|
||||
t.is(metaDescriptionWithFlag(preview, flag), 'Here is some preview text');
|
||||
});
|
||||
|
||||
test('renders with no flag present', (t) => {
|
||||
const preview = 'here is some preview text';
|
||||
|
||||
t.is(metaDescriptionWithFlag(preview), 'Here is some preview text');
|
||||
});
|
16
11ty/shortcodes/metaDescriptionWithFlag.js
Normal file
16
11ty/shortcodes/metaDescriptionWithFlag.js
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports = function(preview, flag = {}) {
|
||||
const initialCap = function(text) {
|
||||
return `${text[0].toUpperCase()}${text.slice(1)}`;
|
||||
};
|
||||
|
||||
if (flag && flag.level === 'avoid') {
|
||||
if (flag.text) {
|
||||
return `${initialCap(
|
||||
flag.level
|
||||
)}: ${flag.text.toLowerCase()}. ${initialCap(preview)}`;
|
||||
}
|
||||
return `${initialCap(flag.level)}: ${preview}`;
|
||||
}
|
||||
|
||||
return initialCap(preview);
|
||||
};
|
Reference in New Issue
Block a user