From 3fb98fcbeab5173acec5222bec7a4adf597e88bb Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 7 Jan 2023 09:53:29 -0400 Subject: extract utility binds, content transform fns towards basic dynamics pt. 1 (#124) --- src/write/bind-utilities.js | 257 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 src/write/bind-utilities.js (limited to 'src/write/bind-utilities.js') diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js new file mode 100644 index 00000000..6632ba30 --- /dev/null +++ b/src/write/bind-utilities.js @@ -0,0 +1,257 @@ +// Ties lots and lots of functions together in a convenient package accessible +// to page write functions. This is kept in a separate file from other write +// areas to keep imports neat and isolated. + +import chroma from 'chroma-js'; + +import { + fancifyFlashURL, + fancifyURL, + getAlbumGridHTML, + getAlbumStylesheet, + getArtistString, + getCarouselHTML, + getFlashGridHTML, + getGridHTML, + getRevealStringFromTags, + getRevealStringFromWarnings, + getThemeString, + generateAdditionalFilesList, + generateAdditionalFilesShortcut, + generateChronologyLinks, + generateCoverLink, + generateInfoGalleryLinks, + generateTrackListDividedByGroups, + generateNavigationLinks, + generateStickyHeadingContainer, + iconifyURL, + img, +} from '../misc-templates.js'; + +import { + replacerSpec, + transformInline, + transformLyrics, + transformMultiline, +} from '../util/transform-content.js'; + +import * as html from '../util/html.js'; + +import {bindOpts, withEntries} from '../util/sugar.js'; +import {getColors} from '../util/colors.js'; +import {bindFind} from '../util/find.js'; + +import link, {getLinkThemeString} from '../util/link.js'; + +import { + getAlbumCover, + getArtistAvatar, + getFlashCover, + getTrackCover, +} from '../util/wiki-data.js'; + +export function bindUtilities({ + language, + to, + wikiData, +}) { + // TODO: Is there some nicer way to define these, + // may8e without totally re-8inding everything for + // each page? + const bound = {}; + + bound.html = html; + + bound.img = bindOpts(img, { + [bindOpts.bindIndex]: 0, + html, + }); + + bound.getColors = bindOpts(getColors, { + chroma, + }); + + bound.getLinkThemeString = bindOpts(getLinkThemeString, { + getColors: bound.getColors, + }); + + bound.getThemeString = bindOpts(getThemeString, { + getColors: bound.getColors, + }); + + bound.link = withEntries(link, (entries) => + entries + .map(([key, fn]) => [key, bindOpts(fn, { + getLinkThemeString: bound.getLinkThemeString, + to, + })])); + + bound.find = bindFind(wikiData, {mode: 'warn'}); + + bound.transformInline = bindOpts(transformInline, { + find: bound.find, + link: bound.link, + replacerSpec, + language, + to, + wikiData, + }); + + bound.transformMultiline = bindOpts(transformMultiline, { + img: bound.img, + to, + transformInline: bound.transformInline, + }); + + bound.transformLyrics = bindOpts(transformLyrics, { + transformInline: bound.transformInline, + transformMultiline: bound.transformMultiline, + }); + + bound.iconifyURL = bindOpts(iconifyURL, { + html, + language, + to, + }); + + bound.fancifyURL = bindOpts(fancifyURL, { + html, + language, + }); + + bound.fancifyFlashURL = bindOpts(fancifyFlashURL, { + [bindOpts.bindIndex]: 2, + html, + language, + + fancifyURL: bound.fancifyURL, + }); + + bound.getRevealStringFromWarnings = bindOpts(getRevealStringFromWarnings, { + html, + language, + }); + + bound.getRevealStringFromTags = bindOpts(getRevealStringFromTags, { + language, + + getRevealStringFromWarnings: bound.getRevealStringFromWarnings, + }); + + bound.getArtistString = bindOpts(getArtistString, { + html, + link: bound.link, + language, + + iconifyURL: bound.iconifyURL, + }); + + bound.getAlbumCover = bindOpts(getAlbumCover, { + to, + }); + + bound.getTrackCover = bindOpts(getTrackCover, { + to, + }); + + bound.getFlashCover = bindOpts(getFlashCover, { + to, + }); + + bound.getArtistAvatar = bindOpts(getArtistAvatar, { + to, + }); + + bound.generateAdditionalFilesShortcut = bindOpts(generateAdditionalFilesShortcut, { + html, + language, + }); + + bound.generateAdditionalFilesList = bindOpts(generateAdditionalFilesList, { + html, + language, + }); + + bound.generateNavigationLinks = bindOpts(generateNavigationLinks, { + link: bound.link, + language, + }); + + bound.generateStickyHeadingContainer = bindOpts(generateStickyHeadingContainer, { + [bindOpts.bindIndex]: 0, + getRevealStringFromTags: bound.getRevealStringFromTags, + html, + img: bound.img, + }); + + bound.generateChronologyLinks = bindOpts(generateChronologyLinks, { + html, + language, + link: bound.link, + wikiData, + + generateNavigationLinks: bound.generateNavigationLinks, + }); + + bound.generateCoverLink = bindOpts(generateCoverLink, { + [bindOpts.bindIndex]: 0, + html, + img: bound.img, + link: bound.link, + language, + to, + wikiData, + + getRevealStringFromTags: bound.getRevealStringFromTags, + }); + + bound.generateInfoGalleryLinks = bindOpts(generateInfoGalleryLinks, { + [bindOpts.bindIndex]: 2, + link: bound.link, + language, + }); + + bound.generateTrackListDividedByGroups = bindOpts(generateTrackListDividedByGroups, { + html, + language, + wikiData, + }); + + bound.getGridHTML = bindOpts(getGridHTML, { + [bindOpts.bindIndex]: 0, + img: bound.img, + html, + language, + + getRevealStringFromTags: bound.getRevealStringFromTags, + }); + + bound.getAlbumGridHTML = bindOpts(getAlbumGridHTML, { + [bindOpts.bindIndex]: 0, + link: bound.link, + language, + + getAlbumCover: bound.getAlbumCover, + getGridHTML: bound.getGridHTML, + }); + + bound.getFlashGridHTML = bindOpts(getFlashGridHTML, { + [bindOpts.bindIndex]: 0, + link: bound.link, + + getFlashCover: bound.getFlashCover, + getGridHTML: bound.getGridHTML, + }); + + bound.getCarouselHTML = bindOpts(getCarouselHTML, { + [bindOpts.bindIndex]: 0, + img: bound.img, + html, + }) + + bound.getAlbumStylesheet = bindOpts(getAlbumStylesheet, { + to, + }); + + return bound; +} -- cgit 1.3.0-6-gf8a5 From 594e8dd46f9e6cc74c680536a1d820eef27133f0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 9 Jan 2023 21:07:16 -0400 Subject: most essential behavior for live-dev-server --- src/write/bind-utilities.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/write/bind-utilities.js') diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js index 6632ba30..1c4dd282 100644 --- a/src/write/bind-utilities.js +++ b/src/write/bind-utilities.js @@ -61,6 +61,7 @@ export function bindUtilities({ const bound = {}; bound.html = html; + bound.language = language; bound.img = bindOpts(img, { [bindOpts.bindIndex]: 0, -- cgit 1.3.0-6-gf8a5 From 4de56d21db5004e5b2c2a49caedee0908b9c6a9f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Jan 2023 17:01:54 -0400 Subject: bind more utilities in bindUtilities --- src/write/bind-utilities.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/write/bind-utilities.js') diff --git a/src/write/bind-utilities.js b/src/write/bind-utilities.js index 1c4dd282..4b037a91 100644 --- a/src/write/bind-utilities.js +++ b/src/write/bind-utilities.js @@ -51,8 +51,11 @@ import { } from '../util/wiki-data.js'; export function bindUtilities({ + absoluteTo, + getSizeOfAdditionalFile, language, to, + urls, wikiData, }) { // TODO: Is there some nicer way to define these, @@ -60,8 +63,15 @@ export function bindUtilities({ // each page? const bound = {}; - bound.html = html; - bound.language = language; + Object.assign(bound, { + absoluteTo, + getSizeOfAdditionalFile, + html, + language, + to, + urls, + wikiData, + }) bound.img = bindOpts(img, { [bindOpts.bindIndex]: 0, -- cgit 1.3.0-6-gf8a5