Skip to content

Commit

Permalink
the format
Browse files Browse the repository at this point in the history
  • Loading branch information
reednel committed Jan 15, 2024
1 parent c2a0184 commit deb6263
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 137 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 8 additions & 16 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ const authorsCollection = defineCollection({
email: z.string().optional(),
image: z.string().optional(),
description: z.string().optional(),
social: z.array(
z.object({
social: z
.array(
z
.object({
name: z.string().optional(),
icon: z.string().optional(),
link: z.string().optional(),
}).optional(),
).optional(),
})
.optional(),
)
.optional(),
draft: z.boolean().optional(),
}),
});
Expand Down Expand Up @@ -43,21 +47,9 @@ const docsCollection = defineCollection({
}),
});

// Pages collection schema
const pagesCollection = defineCollection({
schema: z.object({
title: z.string(),
meta_title: z.string().optional(),
description: z.string().optional(),
image: z.string().optional(),
draft: z.boolean().optional(),
}),
});

// Export collections
export const collections = {
authors: authorsCollection,
blog: blogCollection,
docs: docsCollection,
pages: pagesCollection,
};
14 changes: 7 additions & 7 deletions src/layouts/Base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const { title, meta_title, description, image, noindex, canonical } =
<meta
name="description"
content={plainify(
description ? description : config.metadata.meta_description
description ? description : config.metadata.meta_description,
)}
/>

Expand All @@ -74,15 +74,15 @@ const { title, meta_title, description, image, noindex, canonical } =
<meta
property="og:title"
content={plainify(
meta_title ? meta_title : title ? title : config.site.title
meta_title ? meta_title : title ? title : config.site.title,
)}
/>

<!-- og-description -->
<meta
property="og:description"
content={plainify(
description ? description : config.metadata.meta_description
description ? description : config.metadata.meta_description,
)}
/>
<meta property="og:type" content="website" />
Expand All @@ -95,15 +95,15 @@ const { title, meta_title, description, image, noindex, canonical } =
<meta
name="twitter:title"
content={plainify(
meta_title ? meta_title : title ? title : config.site.title
meta_title ? meta_title : title ? title : config.site.title,
)}
/>

<!-- twitter-description -->
<meta
name="twitter:description"
content={plainify(
description ? description : config.metadata.meta_description
description ? description : config.metadata.meta_description,
)}
/>

Expand All @@ -126,11 +126,11 @@ const { title, meta_title, description, image, noindex, canonical } =

<!-- Katex -->
<link
rel="stylesheet"
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"
integrity="sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ"
crossorigin="anonymous"
>
/>
</head>
<body>
<Header />
Expand Down
10 changes: 5 additions & 5 deletions src/layouts/DocSingle.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import DocBrowser from '@/components/DocBrowser.astro';
import DocContents from '@/components/DocContents.astro';
import DocBrowser from "@/components/DocBrowser.astro";
import DocContents from "@/components/DocContents.astro";
const { post } = Astro.props;
const { Content, headings } = await post.render();
Expand All @@ -21,7 +21,7 @@ const currentPage = new URL(Astro.request.url).pathname;
<!-- Content -->
<main class="py-4 col-9 lg:col-6 overflow-auto">
<article>
<h1 class="mb-4">{ title }</h1>
<h1 class="mb-4">{title}</h1>
<div class="content mb-10">
<Content />
</div>
Expand All @@ -30,10 +30,10 @@ const currentPage = new URL(Astro.request.url).pathname;
<!-- Document Contents (Right) -->
<div class="col-3 sticky top-0 h-screen flex invisible lg:visible">
<div>
<DocContents headings={ headings } />
<DocContents headings={headings} />
</div>
</div>
</div>
</div>
</div>
</section>
</section>
8 changes: 6 additions & 2 deletions src/layouts/components/BlogCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import config from "@/config/config.json";
import { humanize, plainify, slugify } from "@/lib/utils/textConverter";
import { Image } from "astro:assets";
import { FaRegFolder, FaRegUserCircle, FaRegClock } from "react-icons/fa/index.js";
import {
FaRegFolder,
FaRegUserCircle,
FaRegClock,
} from "react-icons/fa/index.js";
import readingTime from "@/lib/utils/readingTime";
const {
Expand Down Expand Up @@ -49,7 +53,7 @@ const { title, image, date, author, categories } = data.data;
))
}
</li>
<li class="mr-4 inline-block ">
<li class="mr-4 inline-block">
<FaRegClock className={"mr-1 -mt-1 inline-block"} />
{readingTime(data.body)}
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/components/BlogSidebar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { tags, categories, allCategories } = Astro.props;
{
categories.map((category: any) => {
const count = allCategories.filter(
(c: any) => c === category
(c: any) => c === category,
).length;
return (
<li>
Expand Down
32 changes: 18 additions & 14 deletions src/layouts/components/DocBrowser.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import docs from "@/config/docs.json";
const { currentPage } = Astro.props;
const currentPageMatch = currentPage ? currentPage.slice(1) : null;
const isCurrentPage = (item) => {
const isCurrentPage = (item: doc_child) => {
if (item.url) {
return item.url.includes(currentPageMatch);
}
return false;
};
const getLinkClasses = (url) => {
const getLinkClasses = (item: doc_child) => {
const baseClasses =
"text-xl block py-1 px-2 my-1 rounded hover:bg-theme-light dark:hover:bg-darkmode-theme-light";
if (isCurrentPage(url)) {
if (isCurrentPage(item)) {
return baseClasses + "rounded bg-theme-light dark:bg-darkmode-theme-light";
} else {
return baseClasses;
Expand All @@ -34,22 +34,26 @@ export interface doc_parent {
const { main }: { main: doc_parent[] } = docs;
---

<nav class="max-h-screen overflow-y-auto mx-8 border-r border-light dark:border-darkmode-light">
<nav
class="max-h-screen overflow-y-auto mx-8 border-r border-light dark:border-darkmode-light"
>
<div class="mx-4 my-8">
<ul>
{
main.map((parent) =>
<h3 class="mt-4">{ parent.name }</h3>
main.map((parent) => (
<>
{ parent.children?.map((child) =>
<li>
<a class={ getLinkClasses(child) } href={ child.url }>
{ child.name }
</a>
</li>
)}
<h3 class="mt-4">{parent.name}</h3>
<>
{parent.children?.map((child) => (
<li>
<a class={getLinkClasses(child)} href={child.url}>
{child.name}
</a>
</li>
))}
</>
</>
)
))
}
</ul>
</div>
Expand Down
58 changes: 31 additions & 27 deletions src/layouts/components/DocContents.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@
const { headings } = Astro.props;
---

<nav class="max-h-screen overflow-y-auto mx-8 border-l border-light dark:border-darkmode-light">
<div class="mx-4 my-8">
<h3 class="my-4">On This Page</h3>
{
headings &&
headings.map((heading) => {
let className = `block p-1 mb-1 rounded hover:bg-theme-light dark:hover:bg-darkmode-theme-light `;
const sizeAndIndent = {
1: `pl-0 text-2xl`,
2: `pl-2 text-xl`,
3: `pl-4 text-lg`,
4: `pl-6 text-base`,
5: `pl-8 text-sm`,
6: `pl-10 text-xs`,
};
className += sizeAndIndent[heading.depth] || "";
return (
<p>
<a href={`#${heading.slug}`} class={className}>
{heading.text}
</a>
</p>
);
})
}
</div>
</nav>
{ headings &&
<nav
class="max-h-screen overflow-y-auto mx-8 border-light dark:border-darkmode-light"
>
<div class="mx-4 my-8">
<h3 class="my-4">On This Page</h3>
{
headings.map((heading: any) => {
let className = `block p-1 mb-1 rounded hover:bg-theme-light dark:hover:bg-darkmode-theme-light `;
const sizeAndIndent: { [key: number]: string } = {
1: `pl-0 text-2xl`,
2: `pl-2 text-xl`,
3: `pl-4 text-lg`,
4: `pl-6 text-base`,
5: `pl-8 text-sm`,
6: `pl-10 text-xs`,
};
className += sizeAndIndent[heading.depth] || "";
return (
<p>
<a href={`#${heading.slug}`} class={className}>
{heading.text}
</a>
</p>
);
})
}
</div>
</nav>
}

8 changes: 2 additions & 6 deletions src/layouts/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,8 @@ const { pathname } = Astro.url;
<div class="mr-4 flex items-center">
<ThemeSwitcher />
</div>

{
settings.search && (
<SearchBar />
)
}

{settings.search && <SearchBar />}
</div>
</nav>
</header>
2 changes: 1 addition & 1 deletion src/layouts/components/Pagination.astro
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ for (let i = 1; i <= totalPages; i++) {
>
{pagination}
</a>
)
),
)}

{/* next page */}
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/components/SearchBar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { IoSearch, IoClose } from "react-icons/io5/index.js";
<input
id="search"
type="text"
class=" bg-transparent border-hidden w-full lg:w-48 focus:outline-none p-0 !mx-0"
class="bg-transparent border-hidden w-full lg:w-48 focus:outline-none p-0 !mx-0"
placeholder="Search..."
/>

Expand Down
18 changes: 12 additions & 6 deletions src/layouts/components/Share.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ const {
folder,
slug,
className,
}: { title?: string; description?: string; folder?: string; slug?: string; className?: string } =
Astro.props;
}: {
title?: string;
description?: string;
folder?: string;
slug?: string;
className?: string;
} = Astro.props;
---

<ul class={`${className}`}>
<li class="inline-block">
<a href=`mailto:?subject=Article: ${title}&amp;body=Check this out: ${base_url}/${folder}/${slug}%0D%0A%0D%0ADescription:%0D%0A${description}%0D%0A%0D%0A`
title="Share by Email"
target="_blank"
<a
href=`mailto:?subject=Article: ${title}&body=Check this out: ${base_url}/${folder}/${slug}%0D%0A%0D%0ADescription:%0D%0A${description}%0D%0A%0D%0A`
title="Share by Email"
target="_blank"
rel="noreferrer noopener"
>
<IoMail />
Expand Down Expand Up @@ -58,4 +64,4 @@ const {
<IoLogoPinterest />
</a>
</li>
</ul>
</ul>
2 changes: 1 addition & 1 deletion src/layouts/components/Social.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ISocial {
rel="noopener noreferrer nofollow"
>
<span class="sr-only">{social.name}</span>
<DynamicIcon class="inline-block" icon={social.icon} />
<DynamicIcon className="inline-block" icon={social.icon} />
</a>
</li>
))
Expand Down
4 changes: 3 additions & 1 deletion src/layouts/components/ThemeSwitcher.astro
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ const {
document.documentElement.classList.toggle("dark");
localStorage.setItem(
"theme",
document.documentElement.classList.contains("dark") ? "dark" : "light"
document.documentElement.classList.contains("dark")
? "dark"
: "light",
);
});
});
Expand Down
Loading

0 comments on commit deb6263

Please sign in to comment.