Skip to content

Commit

Permalink
feat: Use /[owner]/[name] as repository routes (#978)
Browse files Browse the repository at this point in the history
To avoid broken links as much as possible, go back to legacy routes for
repositories, and use /i/ for the index pages.
  • Loading branch information
reobin committed May 8, 2024
1 parent 40b679a commit b7dd685
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
redirects: async () => [
{ source: '/', destination: '/trending', permanent: true },
{ source: '/', destination: '/i/trending', permanent: true },
],
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "4.0.0",
"version": "4.1.0",
"description": "The ultimate resource for vim/neovim color schemes.",
"author": "@reobin",
"license": "GPL-3.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/models/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('repository.key', () => {
describe('repository.route', () => {
it('should return the route of the repository', () => {
const repository = new Repository(dtoLight);
expect(repository.route).toBe('/repositories/owner/repository');
expect(repository.route).toBe('/owner/repository');
});
});

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export default async function IndexPage({ params }: IndexPageProps) {
const validURL = FilterHelper.getURLFromFilter(pageContext.filter);

if (!Object.values(SortOptions).includes(sort)) {
redirect(`/${SortOptions.Trending}/${validURL}`);
redirect(`/i/${SortOptions.Trending}/${validURL}`);
}

if (validURL !== filters.join('/')) {
redirect(`/${sort}/${validURL}`);
redirect(`/i/${sort}/${validURL}`);
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
for (const background of [undefined, ...Object.values(Backgrounds)]) {
for (const editor of [undefined, ...Object.values(Editors)]) {
indexURLs.push({
url: `${process.env.APP_URL}/${sortOption}/${FilterHelper.getURLFromFilter({ background, editor })}`,
url: `${process.env.APP_URL}/i/${sortOption}/${FilterHelper.getURLFromFilter({ background, editor })}`,
lastModified: new Date(),
changeFrequency: 'daily' as const,
priority: 1,
Expand All @@ -25,7 +25,7 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {

const repositories = await RepositoriesService.getAllRepositories();
const repositoryURLs = repositories.map(repository => ({
url: `${process.env.APP_URL}/repositories/${repository.key}`,
url: `${process.env.APP_URL}/${repository.key}`,
lastModified: repository.lastCommitAt,
changeFrequency: 'weekly' as const,
priority: 0.9,
Expand Down
4 changes: 2 additions & 2 deletions src/components/backgroundInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Radio from '@/components/ui/radio';
export default function BackgroundInput() {
const router = useRouter();
const pathname = usePathname();
const pageContext = PageContextHelper.get(pathname.split('/').slice(1));
const pageContext = PageContextHelper.get(pathname.split('/').slice(2));

function onChange(background?: Background) {
delete pageContext.filter.background;
Expand All @@ -21,7 +21,7 @@ export default function BackgroundInput() {
...pageContext.filter,
background,
});
router.push(`/${pageContext.sort}/${url}`);
router.push(`/i/${pageContext.sort}/${url}`);
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/editorInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Radio from '@/components/ui/radio';
export default function EditorInput() {
const router = useRouter();
const pathname = usePathname();
const pageContext = PageContextHelper.get(pathname.split('/').slice(1));
const pageContext = PageContextHelper.get(pathname.split('/').slice(2));

function onChange(editor?: Editor) {
delete pageContext.filter.editor;
Expand All @@ -21,7 +21,7 @@ export default function EditorInput() {
...pageContext.filter,
editor,
});
router.push(`/${pageContext.sort}/${url}`);
router.push(`/i/${pageContext.sort}/${url}`);
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/repositoryPageHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function RepositoryPageHeader({
window.history.back();
return;
}
router.push('/trending');
router.push('/i/trending');
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/searchInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import styles from './index.module.css';
export default function SearchInput() {
const router = useRouter();
const pathname = usePathname();
const pageContext = PageContextHelper.get(pathname.split('/').slice(1));
const pageContext = PageContextHelper.get(pathname.split('/').slice(2));

const [value, setValue] = useState<string>(pageContext.filter.search || '');

Expand All @@ -31,7 +31,7 @@ export default function SearchInput() {
...pageContext.filter,
...(value ? { search: value } : {}),
});
router.replace(`/${pageContext.sort}/${url}`);
router.replace(`/i/${pageContext.sort}/${url}`);
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/sortInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function SortInput({ pageContext }: SortInputProps) {
[styles.active]: pageContext.sort === option,
})}
>
<Link href={`/${option}/${url}`}>
<Link href={`/i/${option}/${url}`}>
<p>{option}</p>
</Link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Header({ pageContext }: HeaderProps) {
[styles.isOnlyBranding]: !pageContext,
})}
>
<Link href="/" className={styles.link}>
<Link href="/i/trending" className={styles.link}>
<Branding />
</Link>
{pageContext && <SortInput pageContext={pageContext} />}
Expand Down
2 changes: 1 addition & 1 deletion src/models/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Repository {
* @returns The route of the repository, used to navigate to the repository page.
*/
get route(): string {
return `/repositories/${this.key}`.toLowerCase();
return `/${this.key}`.toLowerCase();
}

/**
Expand Down

0 comments on commit b7dd685

Please sign in to comment.