Skip to content

Commit

Permalink
[i18nIgnore] Add new subpage handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yanthomasdev committed Feb 28, 2023
1 parent af35eae commit 5fce612
Show file tree
Hide file tree
Showing 158 changed files with 223 additions and 40 deletions.
1 change: 1 addition & 0 deletions scripts/error-docgen.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ function getErrorReferenceEntryHeader(errorTitle) {
title: ${errorTitle}
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'
Expand Down
15 changes: 9 additions & 6 deletions src/components/LeftSidebar/LeftSidebar.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import type { CollectionEntry } from 'astro:content';
import Sponsors from './Sponsors.astro';
import { removeLeadingSlash, removeTrailingSlash } from '../../util';
import { getNav } from '../../util/getNav';
Expand All @@ -7,15 +8,15 @@ import SidebarContent from './SidebarContent.astro';
import SidebarToggleTabGroup from '../TabGroup/SidebarToggleTabGroup';
import CommunityMenu from '../RightSidebar/CommunityMenu.astro';
import ThemeToggleButton from '../Header/ThemeToggleButton';
import { getPageCategory } from '~/util/getPageCategory';
export interface Props {
currentPage: string;
currentPageType: CollectionEntry<'docs'>['data']['type'];
}
const t = useTranslations(Astro);
const { currentPage } = Astro.props as Props;
const { currentPage, currentPageType } = Astro.props as Props;
const currentPageMatch = removeLeadingSlash(removeTrailingSlash(currentPage));
// Group nav menu by sections to properly render.
Expand All @@ -34,9 +35,9 @@ const apiSections = sidebarSections.filter((section) => section.type === 'api');
let activeTab: 'learn' | 'api' = 'learn';
// Certain pages are not in the sidebar nav, so we manually set the active tab based on other factors (e.g. Algolia page category).
const isReference = ['Error Reference', 'Reference'].includes(
getPageCategory(new URL(currentPage, import.meta.url))
);
const referencePagesTypes: Array<typeof currentPageType> = ['error'];
const isReference = referencePagesTypes.includes(currentPageType);
if (isReference) {
activeTab = 'api';
} else {
Expand All @@ -62,12 +63,14 @@ if (isReference) {
defaultActiveTab={activeTab}
sidebarSections={learnSections}
currentPageMatch={currentPageMatch}
currentPageType={currentPageType}
/>
<SidebarContent
type={'api'}
defaultActiveTab={activeTab}
sidebarSections={apiSections}
currentPageMatch={currentPageMatch}
currentPageType={currentPageType}
/>
<li>
<CommunityMenu hideOnLargerScreens={true} />
Expand All @@ -86,7 +89,7 @@ if (isReference) {

<script>
window.addEventListener('DOMContentLoaded', () => {
var target = document.querySelector('[data-current-parent="true"]');
var target = document.querySelector('[data-current-parent="true"]') || document.querySelector('[aria-current="page"]');
target?.scrollIntoView({ block: 'center' });
});
</script>
Expand Down
12 changes: 5 additions & 7 deletions src/components/LeftSidebar/SidebarContent.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import { getLanguageFromURL, removeSubpageSegment } from '../../util';
import type { CollectionEntry } from "astro:content";
import { getLanguageFromURL, getCategoryMainPage } from '../../util';
export interface Props {
type: TabType;
Expand All @@ -10,10 +11,11 @@ export interface Props {
children: Array<{ text: string; slug: string; isFallback?: boolean }>;
}>;
currentPageMatch: string;
currentPageType: CollectionEntry<'docs'>['data']['type'];
}
type TabType = 'learn' | 'api';
const { type, defaultActiveTab, sidebarSections, currentPageMatch } = Astro.props as Props;
const { type, defaultActiveTab, sidebarSections, currentPageMatch, currentPageType } = Astro.props as Props;
const lang = getLanguageFromURL(Astro.url.pathname);
---

Expand Down Expand Up @@ -44,11 +46,7 @@ const lang = getLanguageFromURL(Astro.url.pathname);
<a
href={`${Astro.site?.pathname}${lang}/${slug}/`}
aria-current={`${currentPageMatch.endsWith(slug) ? 'page' : 'false'}`}
data-current-parent={`${
removeSubpageSegment(currentPageMatch).endsWith(removeSubpageSegment(slug))
? 'true'
: 'false'
}`}
data-current-parent={getCategoryMainPage(currentPageType)?.includes(slug).toString()}
>
<Fragment set:html={text} /> {isFallback && <sup class="fallback">EN</sup>}
</a>
Expand Down
18 changes: 18 additions & 0 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export const recipeSchema = baseSchema.extend({
description: z.string(),
});

export const installSchema = baseSchema.extend({
type: z.literal('install'),
});

export const errorSchema = baseSchema.extend({
type: z.literal('error'),
});

export type DeployEntry = CollectionEntry<'docs'> & {
data: z.infer<typeof deploySchema>;
};
Expand All @@ -74,6 +82,14 @@ export type RecipeEntry = CollectionEntry<'docs'> & {
data: z.infer<typeof recipeSchema>;
};

export type InstallEntry = CollectionEntry<'docs'> & {
data: z.infer<typeof installSchema>;
};

export type ErrorEntry = CollectionEntry<'docs'> & {
data: z.infer<typeof errorSchema>;
};

export type IntegrationCategory = z.infer<typeof integrationSchema>['category'];

export function isCmsEntry(entry: CollectionEntry<'docs'>): entry is CmsEntry {
Expand Down Expand Up @@ -109,6 +125,8 @@ const docs = defineCollection({
tutorialSchema,
deploySchema,
recipeSchema,
installSchema,
errorSchema
]),
});

Expand Down
1 change: 1 addition & 0 deletions src/content/docs/de/guides/rss.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: RSS
description: Eine Einführung in RSS in Astro.
type: recipe
---

Astro unterstützt die schnelle, automatische Generierung von RSS-Feeds für Blogs und andere Content-Websites. Weitere Informationen zu RSS-Feeds im Allgemeinen findest du unter [aboutfeeds.com](https://aboutfeeds.com/).
Expand Down
1 change: 1 addition & 0 deletions src/content/docs/de/install/auto.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Automatische Installation von Astro
description: >-
So installierst du Astro mit dem Assistenten create-astro und NPM, PNPM oder
Yarn.
type: install
---
import InstallGuideTabGroup from '~/components/TabGroup/InstallGuideTabGroup.astro';

Expand Down
1 change: 1 addition & 0 deletions src/content/docs/de/install/manual.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Manuelle Installation von Astro
description: 'So installierst du Astro manuell mit NPM, PNPM oder Yarn.'
type: install
---
import InstallGuideTabGroup from '~/components/TabGroup/InstallGuideTabGroup.astro';

Expand Down
1 change: 1 addition & 0 deletions src/content/docs/en/install/auto.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Install Astro with the Automatic CLI
description: 'How to install Astro with NPM, PNPM, or Yarn via the create-astro CLI tool.'
i18nReady: true
type: install
---
import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'

Expand Down
1 change: 1 addition & 0 deletions src/content/docs/en/install/manual.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Install Astro manually
description: 'How to install Astro manually with NPM, PNPM, or Yarn.'
i18nReady: true
type: install
---
import Button from '~/components/Button.astro'
import FileTree from '~/components/FileTree.astro';
Expand Down
1 change: 1 addition & 0 deletions src/content/docs/en/reference/error-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Error reference
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---

import DontEditWarning from '~/components/DontEditWarning.astro'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Astro.clientAddress is not available in current adapter.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand All @@ -20,6 +21,6 @@ The adapter you're using unfortunately does not support `Astro.clientAddress`.

**See Also:**
- [Official integrations](/en/guides/integrations-guide/#official-integrations)
- [Astro.clientAddress](/en/reference/api-reference/#astroclientaddress)
- [Astro.clientAddress](/en/reference/api-reference/#astroclientaddress)


1 change: 1 addition & 0 deletions src/content/docs/en/reference/errors/config-legacy-key.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Legacy configuration detected.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
1 change: 1 addition & 0 deletions src/content/docs/en/reference/errors/config-not-found.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Specified configuration file not found.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Content Schema should not contain slug.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
1 change: 1 addition & 0 deletions src/content/docs/en/reference/errors/csssyntax-error.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: CSS Syntax Error.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Could not import file.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Failed to generate content types.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Missing params property on getStaticPaths route.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand All @@ -32,6 +33,6 @@ Will create the following route: `site.com/blog/1`.

**See Also:**
- [`getStaticPaths()`](/en/reference/api-reference/#getstaticpaths)
- [`params`](/en/reference/api-reference/#params)
- [`params`](/en/reference/api-reference/#params)


Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Invalid value for getStaticPaths route parameter.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down Expand Up @@ -46,6 +47,6 @@ export async function getStaticPaths() {

**See Also:**
- [`getStaticPaths()`](/en/reference/api-reference/#getstaticpaths)
- [`params`](/en/reference/api-reference/#params)
- [`params`](/en/reference/api-reference/#params)


Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: getStaticPaths RSS helper is not available anymore.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: getStaticPaths() function required for dynamic routes.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand All @@ -20,7 +21,7 @@ In [Static Mode](/en/core-concepts/routing/#static-ssg-mode), all routes must be

**See Also:**
- [Dynamic Routes](/en/core-concepts/routing/#dynamic-routes)
- [`getStaticPaths()`](/en/reference/api-reference/#getstaticpaths)
- [Server-side Rendering](/en/guides/server-side-rendering/)
- [`getStaticPaths()`](/en/reference/api-reference/#getstaticpaths)
- [Server-side Rendering](/en/guides/server-side-rendering/)


Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Invalid component arguments.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Content entry frontmatter does not match schema.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Invalid content entry slug.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Invalid frontmatter injection.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Invalid value returned by a getStaticPaths path.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand All @@ -31,6 +32,6 @@ export async function getStaticPaths() {

**See Also:**
- [`getStaticPaths()`](/en/reference/api-reference/#getstaticpaths)
- [`params`](/en/reference/api-reference/#params)
- [`params`](/en/reference/api-reference/#params)


Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Invalid value returned by getStaticPaths.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand All @@ -29,6 +30,6 @@ export async function getStaticPaths() {

**See Also:**
- [`getStaticPaths()`](/en/reference/api-reference/#getstaticpaths)
- [`params`](/en/reference/api-reference/#params)
- [`params`](/en/reference/api-reference/#params)


1 change: 1 addition & 0 deletions src/content/docs/en/reference/errors/invalid-glob.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Invalid glob pattern.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Invalid prerender export.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
title: Content collection frontmatter invalid.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
type: error
---
import DontEditWarning from '~/components/DontEditWarning.astro'

Expand Down
Loading

0 comments on commit 5fce612

Please sign in to comment.