Skip to content

Commit 2559b87

Browse files
committed
TD-31 Add dynamic latest release badge to header and mobile menu
1 parent 6fc344b commit 2559b87

File tree

6 files changed

+88
-12
lines changed

6 files changed

+88
-12
lines changed

astro.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export default defineConfig({
2727
tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 4 },
2828
components: {
2929
Footer: './src/components/overrides/Footer.astro',
30+
Header: './src/components/overrides/Header.astro',
31+
MobileMenuFooter: './src/components/overrides/MobileMenuFooter.astro',
3032
Sidebar: './src/components/overrides/Sidebar.astro',
3133
SocialIcons: './src/components/overrides/SocialIcons.astro'
3234
}

cypress/e2e/release-badge.cy.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const releaseUrl =
2+
'https://github.com/archivesspace/archivesspace/releases/latest'
3+
const title = 'Go to the latest ArchivesSpace release'
4+
const badgeSrc = `https://img.shields.io/github/v/release/archivesspace/archivesspace?label=ArchivesSpace&color=007595`
5+
const altText = 'The latest ArchivesSpace release version'
6+
7+
describe('Release Badge', () => {
8+
it('displays the release badge with the correct data in the header on desktop', () => {
9+
cy.visit('/')
10+
cy.get(
11+
'.page > header:first-child > div:first-child > div:nth-child(3) > a:first-child'
12+
)
13+
.should('have.attr', 'href', releaseUrl)
14+
.should('have.attr', 'title', title)
15+
.within(() => {
16+
cy.get('img')
17+
.should('have.attr', 'src', badgeSrc)
18+
.should('have.attr', 'alt', altText)
19+
})
20+
})
21+
22+
it(
23+
'displays the release badge with the correct data in the mobile menu footer',
24+
{ viewportWidth: 400 },
25+
() => {
26+
cy.visit('/')
27+
cy.get('button[aria-label="Menu"]').click()
28+
cy.get('#starlight__sidebar .mobile-preferences > a:first-child')
29+
.should('have.attr', 'href', releaseUrl)
30+
.should('have.attr', 'title', title)
31+
.within(() => {
32+
cy.get('img')
33+
.should('have.attr', 'src', badgeSrc)
34+
.should('have.attr', 'alt', altText)
35+
})
36+
}
37+
)
38+
})

src/components/ReleaseBadge.astro

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
const releaseUrl =
3+
'https://github.com/archivesspace/archivesspace/releases/latest'
4+
const label = 'ArchivesSpace'
5+
const color = '007595' // dark `--sl-color-accent` via custom.css
6+
const badgeSrc = `https://img.shields.io/github/v/release/archivesspace/archivesspace?label=${label}&color=${color}`
7+
const altText = 'The latest ArchivesSpace release version'
8+
const title = 'Go to the latest ArchivesSpace release'
9+
---
10+
11+
<a href={releaseUrl} title={title}>
12+
<img alt={altText} src={badgeSrc} />
13+
</a>
14+
15+
<style>
16+
a {
17+
display: flex;
18+
align-items: center;
19+
gap: 1rem;
20+
}
21+
@media (min-width: 800px) {
22+
a::after {
23+
content: '';
24+
height: 2rem;
25+
border-inline-end: 1px solid var(--as-color-hairline);
26+
}
27+
}
28+
</style>

src/components/overrides/Header.astro

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
2+
// Via https://github.com/withastro/starlight/blob/23bf960aed36445600b6ccecb2138a5b461e2929/packages/starlight/components/Header.astro
3+
24
import config from 'virtual:starlight/user-config'
3-
import type { Props } from '../props'
5+
import type { Props } from '@astrojs/starlight/props'
46
5-
import LanguageSelect from 'virtual:starlight/components/LanguageSelect'
6-
import Search from 'virtual:starlight/components/Search'
7-
import SiteTitle from 'virtual:starlight/components/SiteTitle'
8-
import SocialIcons from 'virtual:starlight/components/SocialIcons'
9-
import ThemeSelect from 'virtual:starlight/components/ThemeSelect'
7+
import LanguageSelect from '@astrojs/starlight/components/LanguageSelect.astro'
8+
import Search from '@astrojs/starlight/components/Search.astro'
9+
import SiteTitle from '@astrojs/starlight/components/SiteTitle.astro'
10+
import ReleaseBadge from '../ReleaseBadge.astro'
11+
import SocialIcons from './SocialIcons.astro'
12+
import ThemeSelect from '@astrojs/starlight/components/ThemeSelect.astro'
1013
1114
/**
1215
* Render the `Search` component if Pagefind is enabled or the default search component has been overridden.
@@ -24,6 +27,7 @@ const shouldRenderSearch =
2427
{shouldRenderSearch && <Search {...Astro.props} />}
2528
</div>
2629
<div class="sl-hidden md:sl-flex print:hidden right-group">
30+
<ReleaseBadge />
2731
<div class="sl-flex social-icons">
2832
<SocialIcons {...Astro.props} />
2933
</div>

src/components/overrides/MobileMenuFooter.astro

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
---
2-
import LanguageSelect from 'virtual:starlight/components/LanguageSelect'
3-
import SocialIcons from 'virtual:starlight/components/SocialIcons'
4-
import ThemeSelect from 'virtual:starlight/components/ThemeSelect'
5-
import type { Props } from '../props'
2+
// Via https://github.com/withastro/starlight/blob/490c6eff34ab408c4f55777b7b0caa16787dd3d4/packages/starlight/components/MobileMenuFooter.astro
3+
4+
import type { Props } from '@astrojs/starlight/props'
5+
import LanguageSelect from '@astrojs/starlight/components/LanguageSelect.astro'
6+
import ReleaseBadge from '../ReleaseBadge.astro'
7+
import SocialIcons from './SocialIcons.astro'
8+
import ThemeSelect from '@astrojs/starlight/components/ThemeSelect.astro'
69
---
710

811
<div class="mobile-preferences sl-flex">
12+
<ReleaseBadge />
913
<div class="sl-flex social-icons">
1014
<SocialIcons {...Astro.props} />
1115
</div>

src/utils/gitMetadata.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { exec } from 'child_process'
2-
import { promisify } from 'util'
1+
import { exec } from 'node:child_process'
2+
import { promisify } from 'node:util'
33

44
const execPromise = promisify(exec)
55

0 commit comments

Comments
 (0)