Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glossary css #407

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions app/components/Article/Contents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@ const glossaryInjecter = (pageid: string, glossary: Glossary) => {
}
}

const glossaryContents = ({term, pageid, contents, image}: GlossaryEntry) => {
const glossaryPopup = document.createElement('div')
glossaryPopup.className = 'glossary-popup flex-container'

const contentsDiv = document.createElement('div')
contentsDiv.className = 'contents'

const termHeading = document.createElement('h3')
termHeading.textContent = term
contentsDiv.appendChild(termHeading)

const contentsPaddingDiv = document.createElement('div')
contentsPaddingDiv.className = 'padding-bottom-24'
contentsPaddingDiv.innerHTML = contents
contentsDiv.appendChild(contentsPaddingDiv)

if (pageid) {
const viewFullLink = document.createElement('a')
viewFullLink.href = `/${pageid}`
viewFullLink.className = 'button secondary'
viewFullLink.textContent = 'View full definition'
contentsDiv.appendChild(viewFullLink)
}

glossaryPopup.appendChild(contentsDiv)

if (image) {
const imageElem = document.createElement('img')
imageElem.src = image
glossaryPopup.appendChild(imageElem)
}

console.log(glossaryPopup.outerHTML)
return glossaryPopup.outerHTML
Aprillion marked this conversation as resolved.
Show resolved Hide resolved
}

const insertGlossary = (pageid: string, glossary: Glossary) => {
const injecter = glossaryInjecter(pageid, glossary)

Expand Down Expand Up @@ -121,13 +157,7 @@ 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>` : '')
)
entry && addPopup(e as HTMLSpanElement, `glossary-${entry.term}`, glossaryContents(entry))
})

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 or 4 values would make more sense here IMHO, but if the bottom is same as top, repeating it looks suspicious

}
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
Loading