mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-01-22 09:20:00 +00:00
💅 Update ESLint scope (#204)
* lint: let eslint lint all js files in project && auto-fix
* lint: ignore dist, unignore eleventy config
* del unused minified file
* 💅
This commit is contained in:
parent
6f0a29f859
commit
10c0a7296d
118
.eleventy.js
118
.eleventy.js
@ -1,35 +1,42 @@
|
|||||||
const definitionPermalink = require('./11ty/helpers/definitionPermalink')
|
const definitionPermalink = require('./11ty/helpers/definitionPermalink');
|
||||||
const renderDefinitionContentNextEntries = require('./11ty/shortcodes/renderDefinitionContentNextEntries')
|
const renderDefinitionContentNextEntries = require('./11ty/shortcodes/renderDefinitionContentNextEntries');
|
||||||
const findExistingDefinition = require('./11ty/filters/helpers/findExistingDefinition')
|
const findExistingDefinition = require('./11ty/filters/helpers/findExistingDefinition');
|
||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function(config) {
|
||||||
// Add a filter using the Config API
|
// Add a filter using the Config API
|
||||||
config.addFilter('linkTarget', definitionPermalink)
|
config.addFilter('linkTarget', definitionPermalink);
|
||||||
|
|
||||||
config.addFilter('linkIfExistsInCollection', (word, collection) => {
|
config.addFilter('linkIfExistsInCollection', (word, collection) => {
|
||||||
const existingDefinition = findExistingDefinition(word, collection)
|
const existingDefinition = findExistingDefinition(word, collection);
|
||||||
|
|
||||||
if (existingDefinition) {
|
if (existingDefinition) {
|
||||||
return `<a href="${definitionPermalink(existingDefinition.data.slug)}">${word}</a>`
|
return `<a href="${definitionPermalink(
|
||||||
|
existingDefinition.data.slug
|
||||||
|
)}">${word}</a>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<span>${word}</span>`
|
return `<span>${word}</span>`;
|
||||||
})
|
});
|
||||||
|
|
||||||
config.addFilter('linkSubTermIfDefined', (subTermData, collection) => {
|
config.addFilter('linkSubTermIfDefined', (subTermData, collection) => {
|
||||||
const existingDefinition = findExistingDefinition(subTermData.full_title, collection)
|
const existingDefinition = findExistingDefinition(
|
||||||
|
subTermData.full_title,
|
||||||
|
collection
|
||||||
|
);
|
||||||
|
|
||||||
if (existingDefinition) {
|
if (existingDefinition) {
|
||||||
return `<a href="${definitionPermalink(existingDefinition.data.slug)}">${subTermData.text}</a>`
|
return `<a href="${definitionPermalink(existingDefinition.data.slug)}">${
|
||||||
|
subTermData.text
|
||||||
|
}</a>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<span>${subTermData.text}</span>`
|
return `<span>${subTermData.text}</span>`;
|
||||||
})
|
});
|
||||||
|
|
||||||
// just a debug filter to lazily inspect the content of anything in a template
|
// just a debug filter to lazily inspect the content of anything in a template
|
||||||
config.addFilter('postInspect', function(post) {
|
config.addFilter('postInspect', function(post) {
|
||||||
console.log(post)
|
console.log(post);
|
||||||
})
|
});
|
||||||
|
|
||||||
config.addShortcode('definitionFlag', (flag) => {
|
config.addShortcode('definitionFlag', (flag) => {
|
||||||
const cleanText = new Map([
|
const cleanText = new Map([
|
||||||
@ -61,21 +68,24 @@ module.exports = function(config) {
|
|||||||
text: ''
|
text: ''
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
])
|
]);
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
const info = cleanText.get(flag.level.toLowerCase())
|
const info = cleanText.get(flag.level.toLowerCase());
|
||||||
|
|
||||||
const sep = flag.text && info.text ? '—' : ''
|
const sep = flag.text && info.text ? '—' : '';
|
||||||
const text = flag.text ? [ info.text, flag.text ].join(sep) : info.text
|
const text = flag.text ? [info.text, flag.text].join(sep) : info.text;
|
||||||
|
|
||||||
return `<p class="definition-content__signal definition-content__signal--${info.class}">${text}</p>`
|
return `<p class="definition-content__signal definition-content__signal--${info.class}">${text}</p>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<p class="definition-content__signal"></p>'
|
return '<p class="definition-content__signal"></p>';
|
||||||
})
|
});
|
||||||
|
|
||||||
config.addShortcode('renderDefinitionContentNextEntries', renderDefinitionContentNextEntries)
|
config.addShortcode(
|
||||||
|
'renderDefinitionContentNextEntries',
|
||||||
|
renderDefinitionContentNextEntries
|
||||||
|
);
|
||||||
|
|
||||||
// NOTE (ovlb): this will not be remembered as the best code i’ve written. if anyone seeing this has a better solution then the following to achieve sub groups of the definitions: i am happy to get rid of it
|
// NOTE (ovlb): this will not be remembered as the best code i’ve written. if anyone seeing this has a better solution then the following to achieve sub groups of the definitions: i am happy to get rid of it
|
||||||
config.addCollection('tableOfContent', (collection) => {
|
config.addCollection('tableOfContent', (collection) => {
|
||||||
@ -83,14 +93,14 @@ module.exports = function(config) {
|
|||||||
.getFilteredByGlob('./11ty/definitions/*.md')
|
.getFilteredByGlob('./11ty/definitions/*.md')
|
||||||
.filter((word) => !word.data.skip_in_table_of_content)
|
.filter((word) => !word.data.skip_in_table_of_content)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
const { title: firstTitle } = a.data
|
const { title: firstTitle } = a.data;
|
||||||
const { title: secondTitle } = b.data
|
const { title: secondTitle } = b.data;
|
||||||
const sortA = firstTitle.toLowerCase().replace(/^-/, '')
|
const sortA = firstTitle.toLowerCase().replace(/^-/, '');
|
||||||
const sortB = secondTitle.toLowerCase().replace(/^-/, '')
|
const sortB = secondTitle.toLowerCase().replace(/^-/, '');
|
||||||
|
|
||||||
// `localeCompare()` is super cool: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
// `localeCompare()` is super cool: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
||||||
return sortA.localeCompare(sortB)
|
return sortA.localeCompare(sortB);
|
||||||
})
|
});
|
||||||
|
|
||||||
const split = {
|
const split = {
|
||||||
notLetters: {
|
notLetters: {
|
||||||
@ -113,39 +123,39 @@ module.exports = function(config) {
|
|||||||
title: 'T–Z',
|
title: 'T–Z',
|
||||||
definitions: []
|
definitions: []
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
allItems.forEach((word) => {
|
allItems.forEach((word) => {
|
||||||
const { title } = word.data
|
const { title } = word.data;
|
||||||
const { notLetters, aToE, fToL, mToS, tToZ } = split
|
const { notLetters, aToE, fToL, mToS, tToZ } = split;
|
||||||
const sortableTitle = title.replace(/^-/, '')
|
const sortableTitle = title.replace(/^-/, '');
|
||||||
|
|
||||||
if (/^[a-e]/gim.test(sortableTitle)) {
|
if (/^[a-e]/gim.test(sortableTitle)) {
|
||||||
return aToE.definitions.push(word)
|
return aToE.definitions.push(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/^[f-l]/i.test(sortableTitle)) {
|
if (/^[f-l]/i.test(sortableTitle)) {
|
||||||
return fToL.definitions.push(word)
|
return fToL.definitions.push(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/^[m-s]/i.test(sortableTitle)) {
|
if (/^[m-s]/i.test(sortableTitle)) {
|
||||||
return mToS.definitions.push(word)
|
return mToS.definitions.push(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/^[t-z]/i.test(sortableTitle)) {
|
if (/^[t-z]/i.test(sortableTitle)) {
|
||||||
return tToZ.definitions.push(word)
|
return tToZ.definitions.push(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
// no reg ex as the fallback to avoid testing for emojis and numbers
|
// no reg ex as the fallback to avoid testing for emojis and numbers
|
||||||
notLetters.definitions.push(word)
|
notLetters.definitions.push(word);
|
||||||
})
|
});
|
||||||
|
|
||||||
return Object.keys(split).map((key) => {
|
return Object.keys(split).map((key) => {
|
||||||
const { title, definitions } = split[key]
|
const { title, definitions } = split[key];
|
||||||
|
|
||||||
return { title, definitions }
|
return { title, definitions };
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
config.addCollection('definedWords', (collection) => {
|
config.addCollection('definedWords', (collection) => {
|
||||||
return collection
|
return collection
|
||||||
@ -153,20 +163,22 @@ module.exports = function(config) {
|
|||||||
.filter((word) => word.data.defined)
|
.filter((word) => word.data.defined)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
// `localeCompare()` is super cool: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
// `localeCompare()` is super cool: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
||||||
return a.data.title.toLowerCase().localeCompare(b.data.title.toLowerCase())
|
return a.data.title
|
||||||
})
|
.toLowerCase()
|
||||||
})
|
.localeCompare(b.data.title.toLowerCase());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const mdIt = require('markdown-it')({
|
const mdIt = require('markdown-it')({
|
||||||
html: true
|
html: true
|
||||||
})
|
});
|
||||||
const prism = require('markdown-it-prism')
|
const prism = require('markdown-it-prism');
|
||||||
const anchor = require('markdown-it-anchor')
|
const anchor = require('markdown-it-anchor');
|
||||||
|
|
||||||
mdIt.use(prism)
|
mdIt.use(prism);
|
||||||
mdIt.use(anchor)
|
mdIt.use(anchor);
|
||||||
|
|
||||||
config.setLibrary('md', mdIt)
|
config.setLibrary('md', mdIt);
|
||||||
|
|
||||||
// You can return your Config object (optional).
|
// You can return your Config object (optional).
|
||||||
return {
|
return {
|
||||||
@ -177,5 +189,5 @@ module.exports = function(config) {
|
|||||||
templateFormats: ['njk', 'md'],
|
templateFormats: ['njk', 'md'],
|
||||||
htmlTemplateEngine: 'njk',
|
htmlTemplateEngine: 'njk',
|
||||||
markdownTemplateEngine: 'njk'
|
markdownTemplateEngine: 'njk'
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
dist/
|
||||||
|
!.eleventy.js
|
1
_util/create-empty-definitions-min.js
vendored
1
_util/create-empty-definitions-min.js
vendored
@ -1 +0,0 @@
|
|||||||
import slugify from"slugify";import path from"path";import fs from"fs";import{promisify}from"util";const writeFile=promisify(fs.writeFile);import{words}from"./undefined-words";const defintionPath=path.resolve(process.cwd(),"11ty/definitions/"),template="\n---\ntitle: {{title}}\nslug: {{slug}}\ndefined: false\n---\n";export function createDefinitions(){return words.forEach(async t=>{const e=t,i=slugify(t.toLowerCase().replace(/ \([a-z]+\)| ([a-z-]+) slur/i,"")),r=template.replace("{{title}}",e).replace("{{slug}}",i).trim();try{await writeFile(`${defintionPath}/${i}.md`,r,"utf8")}catch(t){console.error(t),process.exit(1)}return!0})}
|
|
@ -1,12 +1,12 @@
|
|||||||
import slugify from 'slugify'
|
import slugify from 'slugify';
|
||||||
import path from 'path'
|
import path from 'path';
|
||||||
import fs from 'fs'
|
import fs from 'fs';
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util';
|
||||||
|
|
||||||
const writeFile = promisify(fs.writeFile)
|
const writeFile = promisify(fs.writeFile);
|
||||||
|
|
||||||
import { words } from './undefined-words'
|
import { words } from './undefined-words';
|
||||||
const defintionPath = path.resolve(process.cwd(), '11ty/definitions/')
|
const defintionPath = path.resolve(process.cwd(), '11ty/definitions/');
|
||||||
|
|
||||||
const template = `
|
const template = `
|
||||||
---
|
---
|
||||||
@ -14,23 +14,28 @@ title: {{title}}
|
|||||||
slug: {{slug}}
|
slug: {{slug}}
|
||||||
defined: false
|
defined: false
|
||||||
---
|
---
|
||||||
`
|
`;
|
||||||
|
|
||||||
export function createDefinitions() {
|
export function createDefinitions() {
|
||||||
return words.forEach(async (word) => {
|
return words.forEach(async (word) => {
|
||||||
const title = word
|
const title = word;
|
||||||
const slug = slugify(word.toLowerCase().replace(/ \([a-z]+\)| ([a-z-]+) slur/i, ''))
|
const slug = slugify(
|
||||||
|
word.toLowerCase().replace(/ \([a-z]+\)| ([a-z-]+) slur/i, '')
|
||||||
|
);
|
||||||
|
|
||||||
const content = template.replace('{{title}}', title).replace('{{slug}}', slug).trim()
|
const content = template
|
||||||
|
.replace('{{title}}', title)
|
||||||
|
.replace('{{slug}}', slug)
|
||||||
|
.trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await writeFile(`${defintionPath}/${slug}.md`, content, 'utf8')
|
await writeFile(`${defintionPath}/${slug}.md`, content, 'utf8');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e);
|
||||||
|
|
||||||
process.exit(1)
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
"build:site": "eleventy",
|
"build:site": "eleventy",
|
||||||
"create-definitions": "bin/create-definitions",
|
"create-definitions": "bin/create-definitions",
|
||||||
"lint": "concurrently npm:lint:*",
|
"lint": "concurrently npm:lint:*",
|
||||||
"lint:css": "stylelint \"assets/css/**/*.scss\"",
|
"lint:css": "stylelint \"assets/css/**/*.scss\" --fix",
|
||||||
"lint:js": "eslint \"11ty/**/*.js\"",
|
"lint:js": "eslint \"**/*.js\" --fix",
|
||||||
"lint:markdown": "markdownlint '**/*.md' --ignore node_modules",
|
"lint:markdown": "markdownlint '**/*.md' --ignore node_modules",
|
||||||
"serve": "concurrently \"npm run serve:site\" \"npm run watch:css\"",
|
"serve": "concurrently \"npm run serve:site\" \"npm run watch:css\"",
|
||||||
"serve:site": "eleventy --serve",
|
"serve:site": "eleventy --serve",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user