mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
chore: format files with prettier
This commit is contained in:
@@ -10,19 +10,18 @@ export interface Props {
|
|||||||
const { centered = false } = Astro.props;
|
const { centered = false } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
<div class={`social-icons ${centered ? "flex" : ""}`}>
|
<div class={`social-icons ${centered ? "flex" : ""}`}>
|
||||||
{
|
{
|
||||||
SOCIALS.filter((social) => social.active).map((social) => (
|
SOCIALS.filter(social => social.active).map(social => (
|
||||||
<LinkButton
|
<LinkButton
|
||||||
href={social.href}
|
href={social.href}
|
||||||
className="link-button"
|
className="link-button"
|
||||||
title={social.name}
|
title={social.name}
|
||||||
>
|
>
|
||||||
<Fragment set:html={socialIcons[social.name]} />
|
<Fragment set:html={socialIcons[social.name]} />
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -59,16 +59,18 @@ Thus, to choose primary color scheme instead of prefers-color-scheme, we have to
|
|||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
The **primaryColorScheme** variable can hold three values_ `"light"`, `"dark"`, `"none"`.
|
The **primaryColorScheme** variable can hold three values\_ `"light"`, `"dark"`, `"none"`.
|
||||||
- `"none"` - system's prefers-color-scheme. (default)
|
|
||||||
|
- `"none"` - system's prefers-color-scheme. (default)
|
||||||
- `"light"` - use light mode as primary color scheme.
|
- `"light"` - use light mode as primary color scheme.
|
||||||
- `"dark"` - use dark mode as primary color scheme.
|
- `"dark"` - use dark mode as primary color scheme.
|
||||||
|
|
||||||
<details><summary>Why 'primaryColorScheme' is not inside config.ts?</summary>
|
<details><summary>Why 'primaryColorScheme' is not inside config.ts?</summary>
|
||||||
|
|
||||||
> To avoid color flickering on page reload, we have to place some JavaScript codes in the inline script tag. It solves the problem of flickering, but as a trade-off, we cannot use ESM imports anymore.
|
> To avoid color flickering on page reload, we have to place some JavaScript codes in the inline script tag. It solves the problem of flickering, but as a trade-off, we cannot use ESM imports anymore.
|
||||||
|
|
||||||
[Click here](https://docs.astro.build/en/core-concepts/astro-components/#client-side-scripts) to know more about Astro's inline script.
|
[Click here](https://docs.astro.build/en/core-concepts/astro-components/#client-side-scripts) to know more about Astro's inline script.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
## Customize color schemes
|
## Customize color schemes
|
||||||
@@ -113,11 +115,12 @@ Here is the detail explaination of color properties.
|
|||||||
| `--color-fill` | Primary color of the website. Usually the main background. |
|
| `--color-fill` | Primary color of the website. Usually the main background. |
|
||||||
| `--color-text-base` | Secondary color of the website. Usually the text color. |
|
| `--color-text-base` | Secondary color of the website. Usually the text color. |
|
||||||
| `--color-accent` | Accent color of the website. Link color, hover color etc. |
|
| `--color-accent` | Accent color of the website. Link color, hover color etc. |
|
||||||
| `--color-card` | Card, scrollbar and code background color. |
|
| `--color-card` | Card, scrollbar and code background color. |
|
||||||
| `--color-card-muted` | Card and scrollbar background color for hover state etc. |
|
| `--color-card-muted` | Card and scrollbar background color for hover state etc. |
|
||||||
| `--color-border` | Border color. Especially used in horizontal row (hr) |
|
| `--color-border` | Border color. Especially used in horizontal row (hr) |
|
||||||
|
|
||||||
Here is an example of changing the light color scheme.
|
Here is an example of changing the light color scheme.
|
||||||
|
|
||||||
```css
|
```css
|
||||||
@layer base {
|
@layer base {
|
||||||
/* lobster color scheme */
|
/* lobster color scheme */
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const { title, author, description, ogImage, datetime, tags } = frontmatter;
|
|||||||
</article>
|
</article>
|
||||||
|
|
||||||
<ul class="tags-container">
|
<ul class="tags-container">
|
||||||
{tags.map((tag) => <Tag name={tag} />)}
|
{tags.map(tag => <Tag name={tag} />)}
|
||||||
</ul>
|
</ul>
|
||||||
</main>
|
</main>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const sortedPosts = getSortedPosts(posts);
|
|||||||
</p>
|
</p>
|
||||||
<div class="social-wrapper">
|
<div class="social-wrapper">
|
||||||
<div class="social-links">Social Links:</div>
|
<div class="social-links">Social Links:</div>
|
||||||
<Socials />
|
<Socials />
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type PagePaths = {
|
|||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const posts = await Astro.glob<Frontmatter>("../../contents/**/*.md");
|
const posts = await Astro.glob<Frontmatter>("../../contents/**/*.md");
|
||||||
|
|
||||||
let postResult: PostResult = posts.map((post) => {
|
let postResult: PostResult = posts.map(post => {
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
slug: slugify(post.frontmatter),
|
slug: slugify(post.frontmatter),
|
||||||
@@ -41,7 +41,7 @@ export async function getStaticPaths() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const pagePaths: PagePaths = getPageNumbers(posts.length).map((pageNum) => ({
|
const pagePaths: PagePaths = getPageNumbers(posts.length).map(pageNum => ({
|
||||||
params: { slug: String(pageNum) },
|
params: { slug: String(pageNum) },
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ const posts = await Astro.glob<Frontmatter>("../contents/**/*.md");
|
|||||||
// List of items to search in
|
// List of items to search in
|
||||||
const searchList = posts
|
const searchList = posts
|
||||||
.filter(({ frontmatter }) => !frontmatter.draft)
|
.filter(({ frontmatter }) => !frontmatter.draft)
|
||||||
.map((post) => ({
|
.map(post => ({
|
||||||
title: post.frontmatter.title,
|
title: post.frontmatter.title,
|
||||||
description: post.frontmatter.description,
|
description: post.frontmatter.description,
|
||||||
headings: post.getHeadings().map((h) => h.text),
|
headings: post.getHeadings().map(h => h.text),
|
||||||
frontmatter: post.frontmatter,
|
frontmatter: post.frontmatter,
|
||||||
}));
|
}));
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export async function getStaticPaths() {
|
|||||||
|
|
||||||
const tags = getUniqueTags(posts);
|
const tags = getUniqueTags(posts);
|
||||||
|
|
||||||
return tags.map((tag) => {
|
return tags.map(tag => {
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
tag,
|
tag,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ let tags = getUniqueTags(posts);
|
|||||||
<Header activeNav="tags" />
|
<Header activeNav="tags" />
|
||||||
<Main pageTitle="Tags" pageDesc="All the tags used in posts.">
|
<Main pageTitle="Tags" pageDesc="All the tags used in posts.">
|
||||||
<ul>
|
<ul>
|
||||||
{tags.map((tag) => <Tag name={tag} size="lg" />)}
|
{tags.map(tag => <Tag name={tag} size="lg" />)}
|
||||||
</ul>
|
</ul>
|
||||||
</Main>
|
</Main>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ import type { MarkdownInstance } from "astro";
|
|||||||
import type { Frontmatter } from "../types";
|
import type { Frontmatter } from "../types";
|
||||||
|
|
||||||
const getPostsByTag = (posts: MarkdownInstance<Frontmatter>[], tag: string) =>
|
const getPostsByTag = (posts: MarkdownInstance<Frontmatter>[], tag: string) =>
|
||||||
posts.filter((post) => slufigyAll(post.frontmatter.tags).includes(tag));
|
posts.filter(post => slufigyAll(post.frontmatter.tags).includes(tag));
|
||||||
|
|
||||||
export default getPostsByTag;
|
export default getPostsByTag;
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import type { Frontmatter } from "../types";
|
|||||||
const getUniqueTags = (posts: MarkdownInstance<Frontmatter>[]) => {
|
const getUniqueTags = (posts: MarkdownInstance<Frontmatter>[]) => {
|
||||||
let tags: string[] = [];
|
let tags: string[] = [];
|
||||||
const filteredPosts = posts.filter(({ frontmatter }) => !frontmatter.draft);
|
const filteredPosts = posts.filter(({ frontmatter }) => !frontmatter.draft);
|
||||||
filteredPosts.forEach((post) => {
|
filteredPosts.forEach(post => {
|
||||||
tags = [...tags, ...post.frontmatter.tags]
|
tags = [...tags, ...post.frontmatter.tags]
|
||||||
.map((tag) => slugifyStr(tag))
|
.map(tag => slugifyStr(tag))
|
||||||
.filter(
|
.filter(
|
||||||
(value: string, index: number, self: string[]) =>
|
(value: string, index: number, self: string[]) =>
|
||||||
self.indexOf(value) === index
|
self.indexOf(value) === index
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ export const slugifyStr = (str: string) => slugger(str);
|
|||||||
const slugify = (frontmatter: Frontmatter) =>
|
const slugify = (frontmatter: Frontmatter) =>
|
||||||
frontmatter.slug ? slugger(frontmatter.slug) : slugger(frontmatter.title);
|
frontmatter.slug ? slugger(frontmatter.slug) : slugger(frontmatter.title);
|
||||||
|
|
||||||
export const slufigyAll = (arr: string[]) => arr.map((str) => slugifyStr(str));
|
export const slufigyAll = (arr: string[]) => arr.map(str => slugifyStr(str));
|
||||||
|
|
||||||
export default slugify;
|
export default slugify;
|
||||||
|
|||||||
Reference in New Issue
Block a user