Skip to content

Commit

Permalink
Move runic parsing to build step
Browse files Browse the repository at this point in the history
Saves resources as runes lib doesn't have to be shipped to client side at all.
  • Loading branch information
stscoundrel committed Oct 26, 2024
1 parent 87650b3 commit 2fab492
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/components/WordDefinition/WordDefinition.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const crosslinks = [
},
]

const runes = 'ᛅᚠ-ᛒᚢᚱᚦᚱ'

describe('WordDefinition component', () => {
test('Does not crash', () => {
const div = document.createElement('div')
Expand All @@ -65,6 +67,7 @@ describe('WordDefinition component', () => {
abbreviations={abbreviations}
similarEntries={[]}
crosslinks={crosslinks}
runes={runes}
/>,
)
})
Expand All @@ -76,6 +79,7 @@ describe('WordDefinition component', () => {
abbreviations={abbreviations}
similarEntries={[]}
crosslinks={crosslinks}
runes={runes}
/>,
).toJSON()
expect(tree).toMatchSnapshot()
Expand All @@ -88,6 +92,7 @@ describe('WordDefinition component', () => {
similarEntries={[]}
abbreviations={abbreviations}
crosslinks={crosslinks}
runes="ᚢᚱ-ᚢᛅᚾᛅ"
/>,
).toJSON()
expect(tree).toMatchSnapshot()
Expand All @@ -100,6 +105,7 @@ describe('WordDefinition component', () => {
abbreviations={abbreviations}
similarEntries={[]}
crosslinks={crosslinks}
runes={runes}
/>,
)
const { root } = tree
Expand All @@ -114,6 +120,7 @@ describe('WordDefinition component', () => {
abbreviations={abbreviations}
similarEntries={[]}
crosslinks={crosslinks}
runes={runes}
/>,
)
const { root } = tree
Expand Down
6 changes: 3 additions & 3 deletions src/components/WordDefinition/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { youngerFuthark } from 'riimut'
import type { Crosslink } from 'scandinavian-dictionary-crosslinker'
import { capitalize, getOlderSpelling } from 'lib/utils/strings'
import { addAbbreviationsToContent, type CombinedAbbreviations } from 'lib/services/abbreviations'
Expand All @@ -13,10 +12,11 @@ interface WordDefinitionProps{
similarEntries: DictionaryEntry[],
abbreviations: CombinedAbbreviations,
crosslinks: Crosslink[],
runes: string,
}

export default function WordDefinition({
entry, similarEntries, abbreviations, crosslinks,
entry, similarEntries, abbreviations, crosslinks, runes,
}: WordDefinitionProps) {
const { word, definitions } = entry
const olderForm = getOlderSpelling(word)
Expand Down Expand Up @@ -57,7 +57,7 @@ export default function WordDefinition({
</p>}

<p>Possible runic inscription in <em>Younger Futhark</em>:
<span className={styles.rune}>{ youngerFuthark.lettersToRunes(word) }</span><br />
<span className={styles.rune}>{ runes }</span><br />
<small>Younger Futhark runes were used from 8th to 12th centuries
in Scandinavia and their overseas settlements</small>
</p>
Expand Down
7 changes: 6 additions & 1 deletion src/pages/word/[word].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import WordDefinition from 'components/WordDefinition'
import Button from 'components/Button'
import { decodeLetter } from 'lib/utils/slugs'
import { getCrossLinks } from 'lib/services/crosslinks'
import { youngerFuthark } from 'riimut'

interface WordPageProps{
entry: DictionaryEntry,
Expand All @@ -25,6 +26,7 @@ interface WordPageProps{
letter: AlphabetLetter,
abbreviations: CombinedAbbreviations,
crosslinks: Crosslink[],
runes: string,
}

interface WordPageParams{
Expand Down Expand Up @@ -88,6 +90,7 @@ export async function getStaticProps(
)[0]
const abbreviations = getAbbreviations(entry)
const crosslinks = getCrossLinks(entry)
const runes = youngerFuthark.lettersToRunes(entry.word)

return {
props: {
Expand All @@ -97,12 +100,13 @@ export async function getStaticProps(
letters,
abbreviations,
crosslinks,
runes,
},
}
}

export default function Word({
entry, similarEntries, letters, abbreviations, crosslinks,
entry, similarEntries, letters, abbreviations, crosslinks, runes,
}) {
const router = useRouter()

Expand All @@ -117,6 +121,7 @@ export default function Word({
similarEntries={similarEntries}
abbreviations={abbreviations}
crosslinks={crosslinks}
runes={runes}
/>
<Button text="Back" action={() => router.back()} />
</Layout>
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/pages/word.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ describe('Word page: render & usage', () => {
},
]

const runes = 'ᚢᚢᛚᚢᛅ'

test('Does not crash', () => {
const div = document.createElement('div')
const root = ReactDOM.createRoot(div)
Expand All @@ -69,6 +71,7 @@ describe('Word page: render & usage', () => {
letters={getAlphabet()}
abbreviations={abbreviations}
crosslinks={crosslinks}
runes={runes}
/>,
)
})
Expand All @@ -81,6 +84,7 @@ describe('Word page: render & usage', () => {
letters={getAlphabet()}
abbreviations={abbreviations}
crosslinks={crosslinks}
runes={runes}
/>,
).toJSON()
expect(tree).toMatchSnapshot()
Expand All @@ -94,6 +98,7 @@ describe('Word page: render & usage', () => {
letters={getAlphabet()}
abbreviations={abbreviations}
crosslinks={[]}
runes={runes}
/>,
).toJSON()
expect(tree).toBeNull()
Expand All @@ -107,6 +112,7 @@ describe('Word page: render & usage', () => {
letters={getAlphabet()}
abbreviations={abbreviations}
crosslinks={crosslinks}
runes={runes}
/>,
)

Expand Down Expand Up @@ -161,6 +167,7 @@ describe('Word page: data fetching', () => {

crosslinks: [],
letters: getAlphabet(),
runes: 'ᛋᛏᛅᚴᛁᛅ',
},
}

Expand Down

0 comments on commit 2fab492

Please sign in to comment.