From 00f1f1397cbec10a2683952aef4273f335b8e035 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sat, 17 Apr 2021 22:36:06 -0500 Subject: [PATCH] Move makeSlug to function --- helpers/build-app-list.js | 14 ++------------ helpers/build-game-list.js | 9 ++------- helpers/build-video-list.js | 7 ++----- helpers/categories.js | 8 ++------ helpers/slug.js | 9 +++++++++ 5 files changed, 17 insertions(+), 30 deletions(-) create mode 100644 helpers/slug.js diff --git a/helpers/build-app-list.js b/helpers/build-app-list.js index 2a4906b..2afdd0a 100644 --- a/helpers/build-app-list.js +++ b/helpers/build-app-list.js @@ -1,7 +1,6 @@ import { promises as fs } from 'fs' import MarkdownIt from 'markdown-it' -import slugify from 'slugify' import axios from 'axios' import statuses, { getStatusName } from './statuses' @@ -9,17 +8,11 @@ import appStoreGenres from './app-store/genres.js' import parseDate from './parse-date' import { eitherMatches } from './matching.js' import { getAppEndpoint } from './app-derived' +import { makeSlug } from './slug.js' const md = new MarkdownIt() - -const makeSlug = name => slugify(name, { - lower: true, - strict: true -}) - - const getTokenLinks = function ( childTokens ) { const tokenList = [] @@ -264,10 +257,7 @@ export default async function () { if (isHeading && token.type === 'inline') { categoryTitle = token.content - categorySlug = slugify(token.content, { - lower: true, - strict: true - }) + categorySlug = makeSlug( token.content ) // appList[categorySlug] = [] } diff --git a/helpers/build-game-list.js b/helpers/build-game-list.js index 0195a7b..0375a9a 100644 --- a/helpers/build-game-list.js +++ b/helpers/build-game-list.js @@ -1,10 +1,8 @@ - -import { promises as fs } from 'fs' -import slugify from 'slugify' import axios from 'axios' // import { statuses } from './build-app-list' import { getAppEndpoint } from './app-derived' +import { makeSlug } from './slug.js' // console.log('process.env.GAMES_SOURCE', process.env.GAMES_SOURCE) @@ -101,10 +99,7 @@ export default async function () { if (isPlayable(game) && statusesTranslations.hasOwnProperty(environmentName(game)) === false) continue // Generate slug - const slug = slugify(game.Games, { - lower: true, - strict: true - }) + const slug = makeSlug( game.Games ) // Find index of game is list so far const gameIndex = gameList.findIndex(game => { diff --git a/helpers/build-video-list.js b/helpers/build-video-list.js index 4a32a97..619f9a0 100644 --- a/helpers/build-video-list.js +++ b/helpers/build-video-list.js @@ -1,11 +1,11 @@ -import slugify from 'slugify' import axios from 'axios' import { fuzzyMatchesWholeWord } from './matching.js' import { byTimeThenNull } from './sort-list.js' import { getVideoEndpoint } from './app-derived.js' import parseDate from './parse-date' +import { makeSlug } from './slug.js' const inTimestamps = ( name, video ) => { @@ -150,10 +150,7 @@ export default async function ( applist ) { if (fetchedVideos[videoId].title === 'Deleted video') continue // Build video slug - const slug = slugify(`${fetchedVideos[videoId].title}-i-${videoId}`, { - lower: true, - strict: true - }) + const slug = makeSlug( `${fetchedVideos[videoId].title}-i-${videoId}` ) const apps = [] // Generate new tag set based on api data diff --git a/helpers/categories.js b/helpers/categories.js index 5effd90..914d71a 100644 --- a/helpers/categories.js +++ b/helpers/categories.js @@ -1,12 +1,8 @@ // Universal JS imports only -import slugify from 'slugify' - +import { makeSlug } from './slug.js' export function makeCategorySlug ( categoryName ) { - return slugify(categoryName, { - lower: true, - strict: true - }) + return makeSlug( categoryName ) } diff --git a/helpers/slug.js b/helpers/slug.js new file mode 100644 index 0000000..9ad21dc --- /dev/null +++ b/helpers/slug.js @@ -0,0 +1,9 @@ +// Universal JS imports only +import slugify from 'slugify' + +export function makeSlug ( name ) { + return slugify(name, { + lower: true, + strict: true + }) +}