diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-10-14 13:35:18 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-02-25 20:03:27 -0400 |
commit | db9b437cbb5a36e5a497345b408205d8da81078f (patch) | |
tree | d277908ef1fde671915c154b9771ebc6a37518d6 | |
parent | dd1e0cbb5f7c85119164b6ab768d0ffcb725ad67 (diff) |
content, client, css: tag gallery: showing all / direct / indirect
-rw-r--r-- | src/content/dependencies/generateArtTagGalleryPage.js | 67 | ||||
-rw-r--r-- | src/content/dependencies/generateArtTagGalleryPageFeaturedLine.js | 23 | ||||
-rw-r--r-- | src/content/dependencies/generateArtTagGalleryPageShowingLine.js | 22 | ||||
-rw-r--r-- | src/static/css/site.css | 47 | ||||
-rw-r--r-- | src/static/js/client/art-tag-gallery-filter.js | 151 | ||||
-rw-r--r-- | src/static/js/client/index.js | 2 | ||||
-rw-r--r-- | src/strings-default.yaml | 39 |
7 files changed, 315 insertions, 36 deletions
diff --git a/src/content/dependencies/generateArtTagGalleryPage.js b/src/content/dependencies/generateArtTagGalleryPage.js index 95d9469a..26a52656 100644 --- a/src/content/dependencies/generateArtTagGalleryPage.js +++ b/src/content/dependencies/generateArtTagGalleryPage.js @@ -3,6 +3,8 @@ import {empty, stitchArrays, unique} from '#sugar'; export default { contentDependencies: [ + 'generateArtTagGalleryPageFeaturedLine', + 'generateArtTagGalleryPageShowingLine', 'generateArtTagNavLinks', 'generateCoverGrid', 'generatePageLayout', @@ -47,6 +49,12 @@ export default { relations.quickDescription = relation('generateQuickDescription', artTag); + relations.featuredLine = + relation('generateArtTagGalleryPageFeaturedLine'); + + relations.showingLine = + relation('generateArtTagGalleryPageShowingLine'); + if (!empty(artTag.extraReadingURLs)) { relations.extraReadingLinks = artTag.extraReadingURLs @@ -90,7 +98,9 @@ export default { data.name = artTag.name; data.color = artTag.color; - data.numArtworks = query.allThings.length; + data.numArtworksIndirectly = query.indirectThings.length; + data.numArtworksDirectly = query.directThings.length; + data.numArtworksTotal = query.allThings.length; data.names = query.allThings.map(thing => thing.name); @@ -113,6 +123,10 @@ export default { query.allThings.map(thing => !query.directThings.includes(thing)); + data.hasMixedDirectIndirect = + data.onlyFeaturedIndirectly.includes(true) && + data.onlyFeaturedIndirectly.includes(false); + return data; }, @@ -134,19 +148,33 @@ export default { extraReadingLinks: relations.extraReadingLinks ?? null, }), - html.tag('p', {class: 'quick-info'}, - language.encapsulate(pageCapsule, 'infoLine', capsule => - (data.numArtworks === 0 - ? language.encapsulate(capsule, 'notFeatured', capsule => [ - language.$(capsule), - html.tag('br'), - language.$(capsule, 'callToAction'), - ]) - : language.$(capsule, { - coverArts: language.countArtworks(data.numArtworks, { - unit: true, - }), - })))), + data.numArtworksTotal === 0 && + html.tag('p', {class: 'quick-info'}, + language.encapsulate(pageCapsule, 'featuredLine.notFeatured', capsule => [ + language.$(capsule), + html.tag('br'), + language.$(capsule, 'callToAction'), + ])), + + relations.featuredLine.clone() + .slots({ + showing: 'all', + count: data.numArtworksTotal, + }), + + data.hasMixedDirectIndirect && [ + relations.featuredLine.clone() + .slots({ + showing: 'direct', + count: data.numArtworksDirectly, + }), + + relations.featuredLine.clone() + .slots({ + showing: 'indirect', + count: data.numArtworksIndirectly, + }), + ], relations.ancestorLinks && html.tag('p', {class: 'quick-info'}, @@ -160,6 +188,17 @@ export default { tags: language.formatUnitList(relations.descendantLinks), })), + data.hasMixedDirectIndirect && [ + relations.showingLine.clone() + .slot('showing', 'all'), + + relations.showingLine.clone() + .slot('showing', 'direct'), + + relations.showingLine.clone() + .slot('showing', 'indirect'), + ], + relations.coverGrid .slots({ links: relations.links, diff --git a/src/content/dependencies/generateArtTagGalleryPageFeaturedLine.js b/src/content/dependencies/generateArtTagGalleryPageFeaturedLine.js new file mode 100644 index 00000000..b4620fa4 --- /dev/null +++ b/src/content/dependencies/generateArtTagGalleryPageFeaturedLine.js @@ -0,0 +1,23 @@ +export default { + extraDependencies: ['html', 'language'], + + slots: { + showing: { + validate: v => v.is('all', 'direct', 'indirect'), + }, + + count: {type: 'number'}, + }, + + generate: (slots, {html, language}) => + language.encapsulate('artTagGalleryPage', pageCapsule => + html.tag('p', {class: 'quick-info'}, + {id: `featured-${slots.showing}-line`}, + + language.$(pageCapsule, 'featuredLine', slots.showing, { + coverArts: + language.countArtworks(slots.count, { + unit: true, + }), + }))), +}; diff --git a/src/content/dependencies/generateArtTagGalleryPageShowingLine.js b/src/content/dependencies/generateArtTagGalleryPageShowingLine.js new file mode 100644 index 00000000..6df4d0e5 --- /dev/null +++ b/src/content/dependencies/generateArtTagGalleryPageShowingLine.js @@ -0,0 +1,22 @@ +export default { + extraDependencies: ['html', 'language'], + + slots: { + showing: { + validate: v => v.is('all', 'direct', 'indirect'), + }, + + count: {type: 'number'}, + }, + + generate: (slots, {html, language}) => + language.encapsulate('artTagGalleryPage', pageCapsule => + html.tag('p', {class: 'quick-info'}, + {id: `showing-${slots.showing}-line`}, + + language.$(pageCapsule, 'showingLine', { + showing: + html.tag('a', {href: '#'}, + language.$(pageCapsule, 'showingLine', slots.showing)), + }))), +}; diff --git a/src/static/css/site.css b/src/static/css/site.css index b5433d6a..e8c2b17f 100644 --- a/src/static/css/site.css +++ b/src/static/css/site.css @@ -1531,11 +1531,6 @@ h1 { font-size: 2em; } -html[data-url-key="localized.home"] #content h1 { - text-align: center; - font-size: 2.5em; -} - #content.flash-index h2 { text-align: center; font-size: 2.5em; @@ -1985,6 +1980,38 @@ h1 a[href="#additional-names-box"]:hover { vertical-align: text-bottom; } +/* Specific pages - homepage */ + +html[data-url-key="localized.home"] #content h1 { + text-align: center; + font-size: 2.5em; +} + +html[data-language-code="preview-en"][data-url-key="localized.home"] #content h1::after { + font-family: cursive; + display: block; + content: "(Preview Build)"; + font-size: 0.8em; +} + +/* Specific pages - art tag gallery */ + +html[data-url-key="localized.artTagGallery"] #featured-direct-line, +html[data-url-key="localized.artTagGallery"] #featured-indirect-line, +html[data-url-key="localized.artTagGallery"] #showing-direct-line, +html[data-url-key="localized.artTagGallery"] #showing-indirect-line { + display: none; +} + +html[data-url-key="localized.artTagGallery"] #showing-all-line a, +html[data-url-key="localized.artTagGallery"] #showing-direct-line a, +html[data-url-key="localized.artTagGallery"] #showing-indirect-line a { + text-decoration: underline; + text-decoration-style: dotted; +} + +/* Specific pages - "Art Tag Network" listing */ + html[data-url-key="localized.listing"][data-url-value0="tags/network"] dl dd:not(#network-top-dl > dd) { margin-left: 20px; margin-bottom: 0; @@ -3074,16 +3101,6 @@ main.long-content .content-sticky-heading-container .content-sticky-subheading-r font-size: 0.9em; } -/* important easter egg mode */ - -html[data-language-code="preview-en"][data-url-key="localized.home"] #content - h1::after { - font-family: cursive; - display: block; - content: "(Preview Build)"; - font-size: 0.8em; -} - /* Layout - Wide (most computers) */ @media (min-width: 900px) { diff --git a/src/static/js/client/art-tag-gallery-filter.js b/src/static/js/client/art-tag-gallery-filter.js new file mode 100644 index 00000000..fd40d1a2 --- /dev/null +++ b/src/static/js/client/art-tag-gallery-filter.js @@ -0,0 +1,151 @@ +/* eslint-env browser */ + +export const info = { + id: 'artTagGalleryFilterInfo', + + featuredAllLine: null, + showingAllLine: null, + showingAllLink: null, + + featuredDirectLine: null, + showingDirectLine: null, + showingDirectLink: null, + + featuredIndirectLine: null, + showingIndirectLine: null, + showingIndirectLink: null, + + gridItems: null, + gridItemsOnlyFeaturedIndirectly: null, + gridItemsFeaturedDirectly: null, +}; + +export function getPageReferences() { + if (document.documentElement.dataset.urlKey !== 'localized.artTagGallery') { + return; + } + + info.featuredAllLine = + document.getElementById('featured-all-line'); + + info.featuredDirectLine = + document.getElementById('featured-direct-line'); + + info.featuredIndirectLine = + document.getElementById('featured-indirect-line'); + + info.showingAllLine = + document.getElementById('showing-all-line'); + + info.showingDirectLine = + document.getElementById('showing-direct-line'); + + info.showingIndirectLine = + document.getElementById('showing-indirect-line'); + + info.showingAllLink = + info.showingAllLine?.querySelector('a') ?? null; + + info.showingDirectLink = + info.showingDirectLine?.querySelector('a') ?? null; + + info.showingIndirectLink = + info.showingIndirectLine?.querySelector('a') ?? null; + + info.gridItems = + Array.from( + document.querySelectorAll('#content .grid-listing .grid-item')); + + info.gridItemsOnlyFeaturedIndirectly = + info.gridItems + .filter(gridItem => gridItem.classList.contains('featured-indirectly')); + + info.gridItemsFeaturedDirectly = + info.gridItems + .filter(gridItem => !gridItem.classList.contains('featured-indirectly')); +} + +function filterArtTagGallery(showing) { + let gridItemsToShow; + + switch (showing) { + case 'all': + gridItemsToShow = info.gridItems; + break; + + case 'direct': + gridItemsToShow = info.gridItemsFeaturedDirectly; + break; + + case 'indirect': + gridItemsToShow = info.gridItemsOnlyFeaturedIndirectly; + break; + } + + for (const gridItem of info.gridItems) { + if (gridItemsToShow.includes(gridItem)) { + gridItem.style.removeProperty('display'); + } else { + gridItem.style.display = 'none'; + } + } +} + +export function addPageListeners() { + const orderShowing = [ + 'all', + 'direct', + 'indirect', + ]; + + const orderFeaturedLines = [ + info.featuredAllLine, + info.featuredDirectLine, + info.featuredIndirectLine, + ]; + + const orderShowingLines = [ + info.showingAllLine, + info.showingDirectLine, + info.showingIndirectLine, + ]; + + const orderShowingLinks = [ + info.showingAllLink, + info.showingDirectLink, + info.showingIndirectLink, + ]; + + for (let index = 0; index < orderShowing.length; index++) { + if (!orderShowingLines[index]) continue; + + let nextIndex = index; + do { + if (nextIndex === orderShowing.length) { + nextIndex = 0; + } else { + nextIndex++; + } + } while (!orderShowingLinks[nextIndex]); + + const currentFeaturedLine = orderFeaturedLines[index]; + const currentShowingLine = orderShowingLines[index]; + const currentShowingLink = orderShowingLinks[index]; + + const nextFeaturedLine = orderFeaturedLines[nextIndex]; + const nextShowingLine = orderShowingLines[nextIndex]; + const nextShowing = orderShowing[nextIndex]; + + currentShowingLink.addEventListener('click', event => { + event.preventDefault(); + + currentFeaturedLine.style.display = 'none'; + currentShowingLine.style.display = 'none'; + + nextFeaturedLine.style.display = 'block'; + nextShowingLine.style.display = 'block'; + + filterArtTagGallery(nextShowing); + }); + } +} diff --git a/src/static/js/client/index.js b/src/static/js/client/index.js index 52d2afd6..63fbc5d6 100644 --- a/src/static/js/client/index.js +++ b/src/static/js/client/index.js @@ -4,6 +4,7 @@ import '../group-contributions-table.js'; import * as additionalNamesBoxModule from './additional-names-box.js'; import * as albumCommentarySidebarModule from './album-commentary-sidebar.js'; +import * as artTagGalleryFilterModule from './art-tag-gallery-filter.js'; import * as artistExternalLinkTooltipModule from './artist-external-link-tooltip.js'; import * as cssCompatibilityAssistantModule from './css-compatibility-assistant.js'; import * as datetimestampTooltipModule from './datetimestamp-tooltip.js'; @@ -24,6 +25,7 @@ import * as wikiSearchModule from './wiki-search.js'; export const modules = [ additionalNamesBoxModule, albumCommentarySidebarModule, + artTagGalleryFilterModule, artistExternalLinkTooltipModule, cssCompatibilityAssistantModule, datetimestampTooltipModule, diff --git a/src/strings-default.yaml b/src/strings-default.yaml index 0765e1ee..b94f8b77 100644 --- a/src/strings-default.yaml +++ b/src/strings-default.yaml @@ -1331,20 +1331,45 @@ artTagInfoPage: # The tag gallery page displays all the artworks that a tag has # been featured in, in one neat grid, with each artwork displaying # its illustrators, as well as a short info line that indicates -# how many artworks the tag's part of. +# how many artworks the tag's been featured in, whether directly, +# indirectly (via descendant tags), both, or neither. If a tag's +# been featured both directly and indirectly, there are buttons +# to switch what's being shown. # artTagGalleryPage: title: "{TAG}" - infoLine: - _: "Featured in {COVER_ARTS}." + descendsFrom: "Descends from {TAGS}." + descendants: "Direct descendants: {TAGS}." + + featuredLine: + all: >- + Featured in {COVER_ARTS}. + + direct: >- + Featured directly in {COVER_ARTS}. + + indirect: >- + Featured indirectly in {COVER_ARTS}. notFeatured: - _: "This tag hasn't been featured in any artworks yet." - callToAction: "Maybe your track will be the first!" + _: >- + This tag hasn't been featured in any artworks yet. - descendsFrom: "Descends from {TAGS}." - descendants: "Direct descendants: {TAGS}." + callToAction: >- + Maybe your track will be the first! + + showingLine: + _: "({SHOWING})" + + all: >- + Showing all artworks. + + indirect: >- + Showing artworks where this tag is only featured indirectly. + + direct: >- + Showing artworks where this tag is featured directly. # # commentaryIndex: |