mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-17 21:53:32 +09:00
jsonGenerator Fixed
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"title": "Astroplate",
|
||||
"base_url": "https://astroplate.netlify.app",
|
||||
"base_path": "/",
|
||||
"trailing_slash": true,
|
||||
"trailing_slash": false,
|
||||
"favicon": "/images/favicon.png",
|
||||
"logo": "/images/logo.png",
|
||||
"logo_darkmode": "/images/logo-darkmode.png",
|
||||
|
||||
@@ -9,6 +9,7 @@ import "@/styles/main.scss";
|
||||
import { AstroFont } from "astro-font";
|
||||
import { ViewTransitions } from "astro:transitions";
|
||||
import SearchModal from "./helpers/SearchModal";
|
||||
import { getLangFromUrl } from "@/lib/utils/languageParser";
|
||||
|
||||
// font families
|
||||
const pf = theme.fonts.font_family.primary;
|
||||
@@ -40,6 +41,8 @@ export interface Props {
|
||||
// distructure frontmatters
|
||||
const { title, meta_title, description, image, noindex, canonical, lang } =
|
||||
Astro.props;
|
||||
|
||||
const language = lang || getLangFromUrl(Astro.url);
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
@@ -108,7 +111,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } =
|
||||
<meta
|
||||
name="description"
|
||||
content={plainify(
|
||||
description ? description : config.metadata.meta_description,
|
||||
description ? description : config.metadata.meta_description
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -121,7 +124,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } =
|
||||
<meta
|
||||
property="og:title"
|
||||
content={plainify(
|
||||
meta_title ? meta_title : title ? title : config.site.title,
|
||||
meta_title ? meta_title : title ? title : config.site.title
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -129,7 +132,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } =
|
||||
<meta
|
||||
property="og:description"
|
||||
content={plainify(
|
||||
description ? description : config.metadata.meta_description,
|
||||
description ? description : config.metadata.meta_description
|
||||
)}
|
||||
/>
|
||||
<meta property="og:type" content="website" />
|
||||
@@ -142,7 +145,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } =
|
||||
<meta
|
||||
name="twitter:title"
|
||||
content={plainify(
|
||||
meta_title ? meta_title : title ? title : config.site.title,
|
||||
meta_title ? meta_title : title ? title : config.site.title
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -150,7 +153,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } =
|
||||
<meta
|
||||
name="twitter:description"
|
||||
content={plainify(
|
||||
description ? description : config.metadata.meta_description,
|
||||
description ? description : config.metadata.meta_description
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -174,7 +177,7 @@ const { title, meta_title, description, image, noindex, canonical, lang } =
|
||||
<body>
|
||||
<TwSizeIndicator />
|
||||
<Header />
|
||||
<SearchModal client:load />
|
||||
<SearchModal lang={language} client:load />
|
||||
<main id="main-content">
|
||||
<slot />
|
||||
</main>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import searchData from ".json/search.json";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import SearchResult, { type ISearchItem } from "./SearchResult";
|
||||
import config from "@/config/config.json";
|
||||
const { default_language } = config.settings;
|
||||
|
||||
const SearchModal = () => {
|
||||
const SearchModal = ({ lang }: { lang: string | undefined }) => {
|
||||
lang = lang || default_language;
|
||||
const [searchString, setSearchString] = useState("");
|
||||
|
||||
// handle input change
|
||||
@@ -39,9 +42,13 @@ const SearchModal = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// filter language specific search data
|
||||
const filterSearchData = searchData.filter((item) => item.lang === lang);
|
||||
|
||||
|
||||
// get search result
|
||||
const startTime = performance.now();
|
||||
const searchResult = doSearch(searchData);
|
||||
const searchResult = doSearch(filterSearchData);
|
||||
const endTime = performance.now();
|
||||
const totalTime = ((endTime - startTime) / 1000).toFixed(3);
|
||||
|
||||
@@ -169,10 +176,15 @@ const SearchModal = () => {
|
||||
name="search"
|
||||
value={searchString}
|
||||
onChange={handleSearch}
|
||||
autoFocus
|
||||
autoComplete="off"
|
||||
/>
|
||||
</div>
|
||||
<SearchResult searchResult={searchResult} searchString={searchString} />
|
||||
<SearchResult
|
||||
searchResult={searchResult}
|
||||
searchString={searchString}
|
||||
lang={lang}
|
||||
/>
|
||||
<div className="search-wrapper-footer">
|
||||
<span className="flex items-center">
|
||||
<kbd>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { slugSelector } from "@/lib/utils/languageParser";
|
||||
import { plainify, titleify } from "@/lib/utils/textConverter";
|
||||
import React from "react";
|
||||
|
||||
export interface ISearchItem {
|
||||
lang: string;
|
||||
group: string;
|
||||
slug: string;
|
||||
frontmatter: {
|
||||
@@ -33,10 +35,13 @@ export interface ISearchGroup {
|
||||
const SearchResult = ({
|
||||
searchResult,
|
||||
searchString,
|
||||
lang
|
||||
}: {
|
||||
searchResult: ISearchItem[];
|
||||
searchString: string;
|
||||
lang: string;
|
||||
}) => {
|
||||
|
||||
// generate search result group
|
||||
const generateSearchGroup = (searchResult: ISearchItem[]) => {
|
||||
const joinDataByGroup: ISearchGroup[] = searchResult.reduce(
|
||||
@@ -83,6 +88,7 @@ const SearchResult = ({
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// match underline
|
||||
const matchUnderline = (text: string, substring: string) => {
|
||||
const parts = text?.split(new RegExp(`(${substring})`, "gi"));
|
||||
@@ -148,12 +154,14 @@ const SearchResult = ({
|
||||
<img
|
||||
src={item.frontmatter.image}
|
||||
alt={item.frontmatter.title}
|
||||
width={100}
|
||||
height={100}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="search-result-item-body">
|
||||
<a
|
||||
href={`/${item.slug}`}
|
||||
href={`${slugSelector(item.slug, lang)}`}
|
||||
className="search-result-item-title search-result-item-link"
|
||||
>
|
||||
{matchUnderline(item.frontmatter.title, searchString)}
|
||||
@@ -188,8 +196,8 @@ const SearchResult = ({
|
||||
{matchUnderline(category, searchString)}
|
||||
{item.frontmatter.categories &&
|
||||
index !==
|
||||
item.frontmatter.categories.length -
|
||||
1 && <>, </>}
|
||||
item.frontmatter.categories.length -
|
||||
1 && <>, </>}
|
||||
</span>
|
||||
),
|
||||
)}
|
||||
@@ -211,7 +219,7 @@ const SearchResult = ({
|
||||
{matchUnderline(tag, searchString)}
|
||||
{item.frontmatter.tags &&
|
||||
index !==
|
||||
item.frontmatter.tags.length - 1 && <>, </>}
|
||||
item.frontmatter.tags.length - 1 && <>, </>}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user