Skip to content

Commit

Permalink
ci(check): Add astro check step (withastro#2341)
Browse files Browse the repository at this point in the history
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
  • Loading branch information
Princesseuh and delucis authored Jan 11, 2023
1 parent 76c0482 commit 335fb88
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 50 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ env:
NODE_OPTIONS: "--max_old_space_size=4096"

jobs:
astrocheck:
name: Check for type issues with astro check
runs-on: ubuntu-latest
env:
FORCE_COLOR: true
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Tools & Dependencies
uses: ./.github/actions/install

- name: Run Check
run: pnpm run check
eslint:
name: Check for code issues with ESLint
runs-on: ubuntu-latest
Expand Down Expand Up @@ -62,4 +76,4 @@ jobs:
uses: ./.github/actions/install

- name: Run Check
run: pnpm run test
run: pnpm run test
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "astro build",
"test": "vitest",
"preview": "astro preview",
"check": "astro check",
"format": "pnpm run format:code",
"format:ci": "pnpm run format:imports && pnpm run format:code",
"format:code": "prettier -w . --cache --plugin-search-dir=.",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Aside.astro
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const { viewBox, d } = icons[type];
<aside class={`content ${type}`} aria-label={title}>
<p class="title" aria-hidden="true">
<span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" {viewBox} width={16} height={16}>
<path fill-rule="evenodd" {d}></path>
<svg xmlns="http://www.w3.org/2000/svg" viewBox={viewBox} width={16} height={16}>
<path fill-rule="evenodd" d={d}></path>
</svg>
</span>
{title}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ContributorList.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export interface Props {
const { githubRepo = 'withastro/docs' } = Astro.props as Props;
const contributorsLink = `https://github.com/${githubRepo}/graphs/contributors`;
const printError = (e) =>
const printError = (e: Error) =>
console.warn(`[error] /src/components/ContributorList.astro\n ${e?.message ?? e}`);
async function getContributors(repo, page = 1) {
async function getContributors(repo: string, page = 1): Promise<{ login: string; id: number }[]> {
try {
const pageSize = 100;
const url = `https://api.github.com/repos/${repo}/contributors?per_page=${pageSize}&page=${page}`;
Expand Down Expand Up @@ -47,7 +47,7 @@ async function getContributors(repo, page = 1) {
}
return data;
} catch (e) {
} catch (e: any) {
printError(e);
return new Array();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DeployGuidesNav.astro
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const services: Service[] = [
---

<CardsNav
{minimal}
minimal={minimal}
class="deploy-guides-nav"
links={services.map(({ title, slug, supports }) => ({
title,
Expand Down
22 changes: 12 additions & 10 deletions src/components/HeadCommon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ import '@fontsource/ibm-plex-mono/400-italic.css';
<!-- Double-click to highlight code blocks (inline only). -->
<script>
document.addEventListener('dblclick', (el) => {
if (el.target.nodeName !== 'CODE') {
return;
}
if (el.target.parentElement.nodeName === 'PRE') {
return;
}
const node = el.target as Node;
if (!node) return;
if (node.nodeName !== 'CODE') return;
if (node.parentElement?.nodeName === 'PRE') return;

let range = new Range();
range.setStart(el.target, 0);
range.setEnd(el.target, 1);
document.getSelection().removeAllRanges();
document.getSelection().addRange(range);
range.setStart(node, 0);
range.setEnd(node, 1);
const selection = document.getSelection();
if (selection) {
selection.removeAllRanges();
selection.addRange(range);
}
});
</script>
<!-- Fathom - beautiful, simple website analytics -->
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/ThemeToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Props {
useLight: string;
useDark: string;
};
isInsideHeader: boolean;
isInsideHeader?: boolean;
}

const themes = ['light', 'dark'];
Expand Down
2 changes: 1 addition & 1 deletion src/components/IntegrationsNav.astro
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function categoryLinksFromPages(pages: MarkdownInstance<Frontmatter>[], category
.filter((page) => page.frontmatter.category === category)
.map((page) => {
const [scope, name] = page.frontmatter.title.split(' ').shift()!.split('/');
const pageUrl = page.url.replace('/en/', `/${lang}/`) + '/';
const pageUrl = page.url!.replace('/en/', `/${lang}/`) + '/';
return {
title:
'<span class="scope">' +
Expand Down
4 changes: 2 additions & 2 deletions src/components/LeftSidebar/LeftSidebar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ if (isReference) {
type={'learn'}
defaultActiveTab={activeTab}
sidebarSections={learnSections}
{currentPageMatch}
currentPageMatch={currentPageMatch}
/>
<SidebarContent
type={'api'}
defaultActiveTab={activeTab}
sidebarSections={apiSections}
{currentPageMatch}
currentPageMatch={currentPageMatch}
/>
<li>
<CommunityMenu hideOnLargerScreens={true} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavGrid/Card.astro
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { href, logo, current, minimal, class: classes, ...attrs } = Astro.props a
<BrandLogo brand={logo} />
<div class="stack">
<h3>
<a {href} aria-current={current ? 'page' : 'false'}>
<a href={href} aria-current={current ? 'page' : 'false'}>
<slot name="title" />
</a>
</h3>
Expand Down
6 changes: 2 additions & 4 deletions src/components/NavGrid/CardsNav.astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ const currentPage = new URL(Astro.request.url).pathname;

<section class:list={['cards-nav', classes]}>
<slot />
<Grid {minimal}>
<Grid minimal={minimal}>
{
links.map(({ href, logo, title, tags }) => (
<Card
{minimal}
{logo}
{href}
{...{ minimal, logo, href }}
current={currentPage.includes(href)}
class={Object.keys(tags || {}).join(' ')}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Video.astro
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const defaultLang = fileCaptions.find((caption) => caption.lang == lang) ? lang
{
fileCaptions.map(({ lang, path }) => (
<track
label={languages[lang]}
label={languages[lang as keyof typeof languages]}
src={path}
kind="captions"
srclang={lang}
Expand Down
4 changes: 2 additions & 2 deletions src/components/tabs/TabbedContent.astro
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ const { tabs } = Astro.props as Props;
tab.setAttribute('role', 'tab');
tab.setAttribute('id', this.id + 'tab' + this.count++);
tab.setAttribute('tabindex', '-1');
tab.parentNode.setAttribute('role', 'presentation');
tab.parentElement?.setAttribute('role', 'presentation');
if (!this.TabStore[i]) this.TabStore.push(new Set());
this.TabStore[i].add(tab);
if ('initial' in tab.dataset && tab.dataset.initial !== 'false') initialTab = i;

// Handle clicking of tabs for mouse users
tab.addEventListener('click', (e) => {
e.preventDefault();
const currentTab: HTMLElement = tablist.querySelector('[aria-selected]');
const currentTab = tablist.querySelector('[aria-selected]');
if (e.currentTarget !== currentTab) {
this.switchTab(e.currentTarget as HTMLElement, i);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/tutorial/TutorialNav.astro
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const isCurrentUnit = (unit: typeof units[number]) =>
href={`/${lang}/${lesson.slug}/`}
aria-current={currentUrl.endsWith(lesson.slug)}
>
<Progress path={lesson.url} />
<Progress path={lesson.url!} />
{index}. {lesson.frontmatter.title}
</a>
</div>
Expand Down
10 changes: 3 additions & 7 deletions src/i18n/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,15 @@ export async function getNav(Astro: AstroGlobal): Promise<NavDict> {
* ---
* <FrameworkComponent label={t('articleNav.nextPage')} />
*/
export function useTranslations(
Astro: Readonly<AstroGlobal>
): (key: UIDictionaryKeys) => string | undefined {
export function useTranslations(Astro: Readonly<AstroGlobal>): (key: UIDictionaryKeys) => string {
const lang = getLanguageFromURL(Astro.url.pathname) || 'en';
return useTranslationsForLang(lang as UILanguageKeys);
}

export function useTranslationsForLang(
lang: UILanguageKeys
): (key: UIDictionaryKeys) => string | undefined {
export function useTranslationsForLang(lang: UILanguageKeys): (key: UIDictionaryKeys) => string {
return function getTranslation(key: UIDictionaryKeys) {
const str = translations[lang]?.[key] || translations[fallbackLang][key];
if (str === undefined) console.error(`Missing translation for “${key}” in “${lang}”.`);
if (str === undefined) throw new Error(`Missing translation for “${key}” in “${lang}”.`);
return str;
};
}
4 changes: 2 additions & 2 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ if (isFallback) canonicalURL.pathname = canonicalURL.pathname.replace(`/${lang}/
</head>

<body>
<Header {currentPage} />
<Header currentPage={currentPage} />
<main class="layout">
<aside id="left-sidebar" class="sidebar">
<slot name="primary-sidebar">
<LeftSidebar {currentPage} />
<LeftSidebar currentPage={currentPage} />
</slot>
</aside>
<aside id="right-sidebar" class="sidebar">
Expand Down
6 changes: 3 additions & 3 deletions src/layouts/DeployGuideLayout.astro
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
import MainLayout from './MainLayout.astro';
import DeployGuidesNav from '../components/DeployGuidesNav.astro';
import BrandLogo from '~/components/BrandLogo.astro';
import BrandLogo, { Props as LogoProps } from '~/components/BrandLogo.astro';
const brand = Astro.url.pathname.replace(/\/$/, '').split('/').pop();
const brand = Astro.url.pathname.replace(/\/$/, '').split('/').pop() as LogoProps['brand'];
---

<MainLayout {...Astro.props}>
<div class="image-wrapper">
<BrandLogo {brand} size="9rem" shape={brand === 'deno' ? 'circle' : 'rounded'} />
<BrandLogo brand={brand} size="9rem" shape={brand === 'deno' ? 'circle' : 'rounded'} />
</div>
<slot />
<DeployGuidesNav minimal />
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/MainLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const overview = t('rightSidebar.overview');
---

<BaseLayout {...Astro.props}>
<RightSidebar slot="secondary-sidebar" {content} {headings} {githubEditUrl} />
<RightSidebar slot="secondary-sidebar" {...{content, headings, githubEditUrl}} />
<PageContent {...{content, previous, next}}>
{
headings && (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/[lang]/404.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ const t = useTranslations(Astro);
</SplashLayout>

<script>
window.addEventListener('load', () => window.fathom.trackGoal('4KN9VI2W', 0));
window.addEventListener('load', () => (window as any).fathom.trackGoal('4KN9VI2W', 0));
</script>
12 changes: 6 additions & 6 deletions src/pages/[lang]/[...fallback].astro
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
import { MarkdownInstance } from 'astro';
import languages from '../../i18n/languages';
import { groupPagesByLang } from '../../util/groupPagesByLang';
export async function getStaticPaths() {
const allPages = await Astro.glob('../**/*.{md,mdx}');
const allPages = await Astro.glob<MarkdownInstance<{}>>('../**/*.{md,mdx}');
const pagesByLang = groupPagesByLang(allPages);
const paths = [];
for (const { url } of pagesByLang.en) {
const slug = url.slice(4);
const slug = url!.slice(4);
for (const lang of Object.keys(languages)) {
if (lang === 'en') continue;
const doesNotNeedFallback = pagesByLang[lang]?.some((p) => p.url.endsWith(slug));
const doesNotNeedFallback = pagesByLang[lang]?.some((p) => p.url!.endsWith(slug));
if (doesNotNeedFallback) continue;
paths.push({ params: { lang, fallback: slug } });
}
}
return paths;
}
const { fallback } = Astro.params;
const englishPages = await Astro.glob('../en/**/*.{md,mdx}');
const { Content } = englishPages.find((p) => p.url.endsWith(fallback));
const englishPages = await Astro.glob<MarkdownInstance<{}>>('../en/**/*.{md,mdx}');
const { Content } = englishPages.find((p) => p.url!.endsWith(Astro.params.fallback as string))!;
---

<Content />

0 comments on commit 335fb88

Please sign in to comment.