|
@@ -1,7 +1,12 @@
|
|
import type { MarkdownInstance } from "astro"
|
|
import type { MarkdownInstance } from "astro"
|
|
import { compareByHas } from "src/utils/compare-by-has"
|
|
import { compareByHas } from "src/utils/compare-by-has"
|
|
|
|
|
|
-export type Project = MarkdownInstance<{
|
|
|
|
|
|
+interface Image {
|
|
|
|
+ src: string
|
|
|
|
+ alt: string
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+interface BaseProjectFrontmatter {
|
|
link: string
|
|
link: string
|
|
title: string
|
|
title: string
|
|
links: Array<{
|
|
links: Array<{
|
|
@@ -11,10 +16,24 @@ export type Project = MarkdownInstance<{
|
|
}>
|
|
}>
|
|
color?: string
|
|
color?: string
|
|
time?: string
|
|
time?: string
|
|
-}>
|
|
|
|
|
|
+ index?: number
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export type BaseProject = MarkdownInstance<BaseProjectFrontmatter>
|
|
|
|
+export type PageProject = MarkdownInstance<
|
|
|
|
+ BaseProjectFrontmatter & {
|
|
|
|
+ cover?: string
|
|
|
|
+ images?: Image[]
|
|
|
|
+ }
|
|
|
|
+>
|
|
|
|
+
|
|
|
|
+export type Project = BaseProject | PageProject
|
|
|
|
|
|
export const sortProjects = (files: any[]): Project[] =>
|
|
export const sortProjects = (files: any[]): Project[] =>
|
|
files.sort(({ frontmatter: a }, { frontmatter: b }) => {
|
|
files.sort(({ frontmatter: a }, { frontmatter: b }) => {
|
|
|
|
+ if (compareByHas(a, b, "index") !== 0)
|
|
|
|
+ return compareByHas(a, b, "index")
|
|
|
|
+
|
|
if (compareByHas(a, b, "date") !== 0) return compareByHas(a, b, "date")
|
|
if (compareByHas(a, b, "date") !== 0) return compareByHas(a, b, "date")
|
|
if (compareByHas(a, b, "time") !== 0) return compareByHas(a, b, "time")
|
|
if (compareByHas(a, b, "time") !== 0) return compareByHas(a, b, "time")
|
|
|
|
|
|
@@ -26,3 +45,10 @@ export const sortProjects = (files: any[]): Project[] =>
|
|
|
|
|
|
return 0
|
|
return 0
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+export const isProjectLink = (href: string) => href.startsWith("/")
|
|
|
|
+
|
|
|
|
+export const needsProjectPage = ({ frontmatter: { link, links } }: Project) => {
|
|
|
|
+ if (isProjectLink(link)) return true
|
|
|
|
+ return links.findIndex(({ href }) => isProjectLink(href)) !== -1
|
|
|
|
+}
|