Skip to content

Commit

Permalink
Merge pull request #407 from StampyAI/glossary
Browse files Browse the repository at this point in the history
glossary css
  • Loading branch information
mruwnik committed Feb 16, 2024
2 parents 8ffc140 + 77ed3be commit 325f5b6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
24 changes: 17 additions & 7 deletions app/components/Article/Contents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,23 @@ const insertGlossary = (pageid: string, glossary: Glossary) => {
*/
fragment.querySelectorAll('.glossary-entry').forEach((e) => {
const entry = glossaryEntry(e)
entry &&
addPopup(
e as HTMLSpanElement,
`glossary-${entry.term}`,
`<div>${entry.contents}</div>` +
(entry.pageid ? `<br><a href="/${entry.pageid}">See more...</a>` : '')
)
if (!entry) return undefined
const link =
entry.pageid &&
`<a href="/${entry.pageid}" class="button secondary">View full definition</a>`
const image = entry.image && `<img src="${entry.image}"/>`
addPopup(
e as HTMLSpanElement,
`glossary-${entry.term}`,
`<div class="glossary-popup flex-container black">
<div class="contents">
<h3>${entry.term}</h3>
<div class="padding-bottom-24">${entry.contents}</div>
${link || ''}
</div>
${image || ''}
</div>`
)
})

return fragment
Expand Down
10 changes: 9 additions & 1 deletion app/components/Article/article.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ article .link-popup {
position: absolute;
display: inline-block;
font: var(--baseFont);
padding: 5px 10px;
margin-left: 10px;
max-width: 35%;
z-index: 2;
Expand All @@ -77,6 +76,15 @@ article .link-popup::after {
right: 100%;
}

article .link-popup .glossary-popup > .contents {
padding: var(--spacing-24) var(--spacing-40) var(--spacing-24);
}
article .link-popup .glossary-popup > img {
width: 100%;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
}

article .link-popup.shown {
visibility: visible;
opacity: 1;
Expand Down
7 changes: 5 additions & 2 deletions app/server-utils/stampy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type GlossaryEntry = {
term: string
pageid: PageId
contents: string
image: string
}
export type Glossary = {
[key: string]: GlossaryEntry
Expand Down Expand Up @@ -147,6 +148,7 @@ type GlossaryRow = CodaRowCommon & {
phrase: string
aliases: string
'UI ID': string
image: Entity
}
}
type BannersRow = CodaRowCommon & {
Expand Down Expand Up @@ -326,12 +328,13 @@ export const loadGlossary = withCache('loadGlossary', async () => {
const phrases = [values.phrase, ...values.aliases.split('\n')]
const item = {
pageid,
image: values.image?.url,
contents: renderText(pageid, extractText(values.definition)),
}
return phrases
.map((i) => extractText(i.toLowerCase()))
.map((i) => extractText(i))
.filter(Boolean)
.map((phrase) => [phrase, {term: phrase, ...item}])
.map((phrase) => [phrase.toLowerCase(), {term: phrase, ...item}])
})
.flat()
)
Expand Down
File renamed without changes
File renamed without changes

0 comments on commit 325f5b6

Please sign in to comment.