Skip to content

Commit f4242cf

Browse files
committed
Show git info in sidebar in dev mode and test for it
Pass env vars to Cypress via npm scripts Update about dev docs Make import aliases explicit per directory Update Sidebar nav link hover styles
1 parent b75e619 commit f4242cf

File tree

9 files changed

+111
-13
lines changed

9 files changed

+111
-13
lines changed

astro.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export default defineConfig({
2626
sidebar,
2727
tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 4 },
2828
components: {
29-
Footer: './src/components/overrides/Footer.astro'
29+
Footer: './src/components/overrides/Footer.astro',
30+
Sidebar: './src/components/overrides/Sidebar.astro'
3031
}
3132
})
3233
]

cypress/e2e/sidebar.cy.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe('Sidebar', () => {
2+
it('shows git metadata only in development mode', () => {
3+
cy.visit('/')
4+
if (Cypress.env('MODE') === 'production') {
5+
cy.get('#starlight__sidebar > .sidebar-content > footer').should(
6+
'not.exist'
7+
)
8+
}
9+
if (Cypress.env('MODE') === 'development') {
10+
cy.get('#starlight__sidebar > .sidebar-content > footer')
11+
}
12+
})
13+
})

cypress/e2e/sitemap.cy.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
describe('Sitemap', () => {
2-
it('assets are present', () => {
3-
cy.request('/sitemap-index.xml')
4-
cy.request('/sitemap-0.xml')
5-
})
2+
if (Cypress.env('MODE') === 'production') {
3+
it('assets are present', () => {
4+
cy.request('/sitemap-index.xml')
5+
cy.request('/sitemap-0.xml')
6+
})
7+
}
68

79
it('is linked from each page', () => {
810
cy.visit('/')

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"build": "astro build",
1515
"preview": "astro preview",
1616
"astro": "astro",
17-
"test": "cypress run",
17+
"test:dev": "cypress run --env MODE=development",
18+
"test:prod": "cypress run --env MODE=production",
19+
"test": "npm run test:prod",
1820
"prettier:check": "prettier --check .",
1921
"prettier:fix": "prettier --write .",
2022
"stylelint:check": "stylelint '**/*.{astro,css}' -f verbose",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
import type { Props } from '@astrojs/starlight/props'
3+
import Default from '@astrojs/starlight/components/Sidebar.astro'
4+
import gitMetadata from '@utils/gitMetadata.mjs'
5+
6+
const isDev = import.meta.env.DEV
7+
---
8+
9+
<Default {...Astro.props}><slot /></Default>
10+
11+
{
12+
isDev && (
13+
<footer>
14+
<p>
15+
<svg
16+
aria-hidden="true"
17+
focusable="false"
18+
class="octicon octicon-git-branch"
19+
viewBox="0 0 16 16"
20+
width="16"
21+
height="16"
22+
fill="currentColor"
23+
style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible"
24+
>
25+
<path d="M9.5 3.25a2.25 2.25 0 1 1 3 2.122V6A2.5 2.5 0 0 1 10 8.5H6a1 1 0 0 0-1 1v1.128a2.251 2.251 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.5 0v1.836A2.493 2.493 0 0 1 6 7h4a1 1 0 0 0 1-1v-.628A2.25 2.25 0 0 1 9.5 3.25Zm-6 0a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Zm8.25-.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM4.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z" />
26+
</svg>
27+
{gitMetadata}
28+
</p>
29+
</footer>
30+
)
31+
}
32+
33+
<style>
34+
footer {
35+
margin-top: auto;
36+
padding-bottom: 0.5rem;
37+
font-size: 0.75rem;
38+
color: var(--sl-color-gray-3);
39+
text-align: center;
40+
41+
p {
42+
text-wrap-mode: nowrap;
43+
overflow-x: scroll;
44+
}
45+
}
46+
47+
@media (min-width: 800px) {
48+
footer {
49+
padding-bottom: 0;
50+
text-align: left;
51+
}
52+
}
53+
</style>

src/content/docs/about/development.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Development and maintenance
2+
title: Development
33

44
# This is the last page in the sidebar, so point to Home next instead of
55
# the Help Center which comes after this page in the sidebar
@@ -8,7 +8,7 @@ next:
88
label: Home
99
---
1010

11-
Tech Docs is a [Node.js](https://nodejs.org) application, built with [Astro](https://astro.build/) and its [Starlight](https://starlight.astro.build/) documentation site framework. The source code is hosted on [GitHub](https://github.com/archivesspace/tech-docs). The site is statically built and hosted via [Cloudflare Pages](https://pages.cloudflare.com/). Content is written in [Markdown](./authoring#commonly-used-markdown-syntax). When the source code changes, a new set of static files are generated and published shortly after.
11+
Tech Docs is a [Node.js](https://nodejs.org) application, built with [Astro](https://astro.build/) and its [Starlight](https://starlight.astro.build/) documentation site framework. The source code is hosted on [GitHub](https://github.com/archivesspace/tech-docs). The site is statically built and (temporarily) hosted via [Cloudflare Pages](https://pages.cloudflare.com/). Content is written in [Markdown](./authoring#commonly-used-markdown-syntax). When the source code changes, a new set of static files are generated and published shortly after.
1212

1313
## Dependencies
1414

@@ -147,17 +147,17 @@ npm test
147147

148148
### Code style
149149

150-
Nearly all files in the Tech Docs code base get formatted by [Prettier](https://prettier.io/) to ensure consistent readability and syntax. Run Prettier locally to find errors and automatically fix errors where possible:
150+
Nearly all files in the Tech Docs code base get formatted by [Prettier](https://prettier.io/) to ensure consistent readability and syntax. Run Prettier locally to find format errors and automatically fix them when possible:
151151

152152
```sh
153-
# Check formatting of .md, .css, .astro, .js, .yml files, etc.
153+
# Check formatting of .md, .css, .astro, .js, .yml, etc. files
154154
npm run prettier:check
155155

156156
# Fix any errors that can be overwritten automatically
157157
npm run prettier:fix
158158
```
159159

160-
All CSS in .css and .astro files are linted by [Stylelint](https://stylelint.io/) to help avoid errors and enforce conventions. Run Stylelint locally to find lint errors and automatically fix errors where possible:
160+
All CSS in .css and .astro files are linted by [Stylelint](https://stylelint.io/) to help avoid errors and enforce conventions. Run Stylelint locally to find lint errors and automatically fix them when possible:
161161

162162
```sh
163163
# Check all CSS

src/styles/custom.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ body > .page > .header {
6666
#starlight__sidebar ul.top-level ul > li {
6767
border-color: transparent;
6868

69-
&:hover {
69+
&:not(:has(> details:first-child)):hover {
7070
border-inline-start-color: var(--sl-color-gray-4);
7171
}
7272
}

src/utils/gitMetadata.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { exec } from 'child_process'
2+
import { promisify } from 'util'
3+
4+
const execPromise = promisify(exec)
5+
6+
export default await gitMetadata()
7+
8+
/**
9+
* @returns {Promise<string>} The current branch and latest commit hash,
10+
* eg, `${branch}-${commit}`
11+
*/
12+
async function gitMetadata() {
13+
try {
14+
const { stdout, stderr } = await execPromise(
15+
'echo `git rev-parse --abbrev-ref HEAD 2>/dev/null`-`git rev-parse --short HEAD 2>/dev/null`'
16+
)
17+
if (stderr) {
18+
throw new Error(`Stderr: ${stderr}`)
19+
}
20+
21+
return stdout.trim()
22+
} catch (error) {
23+
throw new Error(`Error: ${error.message}`)
24+
}
25+
}

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"compilerOptions": {
44
"baseUrl": ".",
55
"paths": {
6-
"@*": ["src/*"]
6+
"@components/*": ["src/components/*"],
7+
"@images/*": ["src/images/*"],
8+
"@utils/*": ["src/utils/*"]
79
}
810
}
911
}

0 commit comments

Comments
 (0)