Skip to content

Commit 97a41f3

Browse files
committed
TD-31 Add dynamic latest release badge to header and mobile menu
1 parent 8bae2f6 commit 97a41f3

File tree

6 files changed

+113
-8
lines changed

6 files changed

+113
-8
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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('.page > header:first-child > div:first-child > div:nth-child(3) > a:first-child')
11+
.should('have.attr', 'href', releaseUrl)
12+
.should('have.attr', 'title', title)
13+
.within(() => {
14+
cy.get('img')
15+
.should('have.attr', 'src', badgeSrc)
16+
.should('have.attr', 'alt', altText);
17+
});
18+
})
19+
20+
it('displays the release badge with the correct data in the mobile menu footer',
21+
{ viewportWidth: 400 },
22+
() => {
23+
cy.visit('/')
24+
cy.get('button[aria-label="Menu"]')
25+
.click()
26+
cy.get('#starlight__sidebar .mobile-preferences > a:first-child')
27+
.should('have.attr', 'href', releaseUrl)
28+
.should('have.attr', 'title', title)
29+
.within(() => {
30+
cy.get('img')
31+
.should('have.attr', 'src', badgeSrc)
32+
.should('have.attr', 'alt', altText);
33+
});
34+
}
35+
)
36+
})

src/components/ReleaseBadge.astro

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
a::after {
22+
content: '';
23+
height: 2rem;
24+
border-inline-end: 1px solid var(--as-color-hairline);
25+
}
26+
</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>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
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'
9+
---
10+
11+
<div class="mobile-preferences sl-flex">
12+
<ReleaseBadge />
13+
<div class="sl-flex social-icons">
14+
<SocialIcons {...Astro.props} />
15+
</div>
16+
<ThemeSelect {...Astro.props} />
17+
<LanguageSelect {...Astro.props} />
18+
</div>
19+
20+
<style>
21+
.social-icons {
22+
margin-inline-end: auto;
23+
gap: 1rem;
24+
align-items: center;
25+
padding-block: 1rem;
26+
}
27+
.social-icons:empty {
28+
display: none;
29+
}
30+
.mobile-preferences {
31+
justify-content: space-between;
32+
flex-wrap: wrap;
33+
border-top: 1px solid var(--sl-color-gray-6);
34+
column-gap: 1rem;
35+
padding: 0.5rem 0;
36+
}
37+
</style>

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)