-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
b75e619
commit f4242cf
Showing
9 changed files
with
111 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe('Sidebar', () => { | ||
it('shows git metadata only in development mode', () => { | ||
cy.visit('/') | ||
if (Cypress.env('MODE') === 'production') { | ||
cy.get('#starlight__sidebar > .sidebar-content > footer').should( | ||
'not.exist' | ||
) | ||
} | ||
if (Cypress.env('MODE') === 'development') { | ||
cy.get('#starlight__sidebar > .sidebar-content > footer') | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
import type { Props } from '@astrojs/starlight/props' | ||
import Default from '@astrojs/starlight/components/Sidebar.astro' | ||
import gitMetadata from '@utils/gitMetadata.mjs' | ||
const isDev = import.meta.env.DEV | ||
--- | ||
|
||
<Default {...Astro.props}><slot /></Default> | ||
|
||
{ | ||
isDev && ( | ||
<footer> | ||
<p> | ||
<svg | ||
aria-hidden="true" | ||
focusable="false" | ||
class="octicon octicon-git-branch" | ||
viewBox="0 0 16 16" | ||
width="16" | ||
height="16" | ||
fill="currentColor" | ||
style="display:inline-block;user-select:none;vertical-align:text-bottom;overflow:visible" | ||
> | ||
<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" /> | ||
</svg> | ||
{gitMetadata} | ||
</p> | ||
</footer> | ||
) | ||
} | ||
|
||
<style> | ||
footer { | ||
margin-top: auto; | ||
padding-bottom: 0.5rem; | ||
font-size: 0.75rem; | ||
color: var(--sl-color-gray-3); | ||
text-align: center; | ||
|
||
p { | ||
text-wrap-mode: nowrap; | ||
overflow-x: scroll; | ||
} | ||
} | ||
|
||
@media (min-width: 800px) { | ||
footer { | ||
padding-bottom: 0; | ||
text-align: left; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { exec } from 'child_process' | ||
import { promisify } from 'util' | ||
|
||
const execPromise = promisify(exec) | ||
|
||
export default await gitMetadata() | ||
|
||
/** | ||
* @returns {Promise<string>} The current branch and latest commit hash, | ||
* eg, `${branch}-${commit}` | ||
*/ | ||
async function gitMetadata() { | ||
try { | ||
const { stdout, stderr } = await execPromise( | ||
'echo `git rev-parse --abbrev-ref HEAD 2>/dev/null`-`git rev-parse --short HEAD 2>/dev/null`' | ||
) | ||
if (stderr) { | ||
throw new Error(`Stderr: ${stderr}`) | ||
} | ||
|
||
return stdout.trim() | ||
} catch (error) { | ||
throw new Error(`Error: ${error.message}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters