@bbki.ng/site 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 1.0.12
4
+
5
+ ## 1.0.11
6
+
3
7
  ## 1.0.10
4
8
 
5
9
  ## 1.0.9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "url": "git+https://github.com/bbbottle/bbki.ng.git"
17
17
  },
18
18
  "dependencies": {
19
- "@bbki.ng/components": "workspace:2.1.30",
19
+ "@bbki.ng/components": "workspace:2.1.31",
20
20
  "@supabase/supabase-js": "^1.30.6",
21
21
  "classnames": "2.3.1",
22
22
  "react": "^18.0.0",
package/src/app.tsx CHANGED
@@ -49,7 +49,7 @@ export const App = () => {
49
49
  return (
50
50
  <SWR>
51
51
  <HotKeyNav>
52
- <Stickers />
52
+ {/*<Stickers />*/}
53
53
  <GlobalLoadingStateProvider>
54
54
  <Routes>
55
55
  <Route path="/" element={<Layout />}>
@@ -1,11 +1,6 @@
1
- import * as 说明书 from "./bbking-manual.mdx";
2
1
  import * as 回暖 from "./warming-up.mdx";
3
- import * as 可以攻玉 from "./quote.mdx";
4
2
  import * as 离开 from "./travel.mdx";
5
3
  import * as 降温 from "./cooldown.mdx";
6
- import * as 与或非禁区 from "./anti-logic.mdx";
7
- import * as 没有女人的男人们 from "./men-without-women.mdx";
8
- import * as 一天计划 from "./movie-day.mdx";
9
4
  import * as 大雪 from "./fall.mdx";
10
5
  import * as 大寒 from "./major-cold.mdx";
11
6
  import * as 春雨 from "./spring-rain.mdx";
@@ -13,9 +8,6 @@ import * as 春寒 from "./spring-cooldown.mdx";
13
8
  import * as 入夏 from "./web-burnning.mdx";
14
9
  import * as 六月 from "./black-river.mdx";
15
10
  import * as 立秋 from "./liqiu.mdx";
16
- import * as 春风模拟 from "./pseudo-spring.mdx";
17
- import * as 庆典 from "./celebration.mdx";
18
- import * as 爱情 from "./love.mdx";
19
11
  import * as 照片 from "./photos.mdx";
20
12
  import * as 小乌鸦 from "./xwy.mdx";
21
13
  import * as 我要看雪 from "./xwy-and-snowing.mdx";
@@ -30,13 +22,8 @@ import * as 站一下 from "./moment.mdx";
30
22
  import * as 干衣服 from "./cloth.mdx";
31
23
 
32
24
  export const MdxArticleList = [
33
- 说明书,
34
- 与或非禁区,
35
- 可以攻玉,
36
25
  离开,
37
26
  降温,
38
- 没有女人的男人们,
39
- 一天计划,
40
27
  大雪,
41
28
  大寒,
42
29
  回暖,
@@ -45,9 +32,6 @@ export const MdxArticleList = [
45
32
  入夏,
46
33
  六月,
47
34
  立秋,
48
- 春风模拟,
49
- 庆典,
50
- 爱情,
51
35
  照片,
52
36
  小乌鸦,
53
37
  我要看雪,
@@ -12,7 +12,8 @@ export const ROUTE_NAME = {
12
12
  unknown: "未知",
13
13
  };
14
14
 
15
- export const GITHUB_REPO_ADDRESS = "https://github.com/bbbottle/bottle/tree/main/packages/site";
15
+ export const GITHUB_REPO_ADDRESS =
16
+ "https://github.com/bbbottle/bottle/tree/main/packages/site";
16
17
  export const OSS_ADDRESS = "https://zjh-im-res.oss-cn-shenzhen.aliyuncs.com";
17
18
  export const API_ENDPOINT = "https://api.bbki.ng";
18
19
  export const API = {
@@ -21,4 +22,5 @@ export const API = {
21
22
  MOVIES: "movies",
22
23
  IMAGES: "images",
23
24
  BOOKS: "books",
25
+ POSTS: "posts",
24
26
  };
@@ -0,0 +1,34 @@
1
+ import { API } from "@/constants/routes";
2
+ import useSWR from "swr";
3
+ import { useContext, useEffect } from "react";
4
+ import { GlobalLoadingContext } from "@/global_loading_state_provider";
5
+
6
+ export const usePosts = (name: string = "", suspense?: boolean) => {
7
+ const { data, error } = useSWR(API.POSTS, {
8
+ revalidateOnFocus: false,
9
+ suspense,
10
+ });
11
+
12
+ let isLoading = !data && !error;
13
+ const { setIsLoading } = useContext(GlobalLoadingContext);
14
+ const titleList = isLoading
15
+ ? []
16
+ : data.map((p: any) => ({
17
+ name: p.title,
18
+ to: p.title,
19
+ }));
20
+
21
+ useEffect(() => {
22
+ setIsLoading(isLoading);
23
+ }, [isLoading]);
24
+
25
+ const posts =
26
+ isLoading || name == "" ? data : data.find((p: any) => p.title == name);
27
+
28
+ return {
29
+ posts: posts,
30
+ titleList,
31
+ isError: error,
32
+ isLoading: !data && !error,
33
+ };
34
+ };
@@ -1,10 +1,20 @@
1
1
  import React from "react";
2
- import { Article } from "@bbki.ng/components";
2
+ import { LinkList } from "@bbki.ng/components";
3
3
 
4
4
  export const Cover = (props: { className: string }) => {
5
5
  return (
6
- <Article title="">
7
- <div className="bg-white">This page intentionally left blank</div>
8
- </Article>
6
+ <LinkList
7
+ links={[
8
+ {
9
+ to: "/projects",
10
+ name: "cd /projects",
11
+ },
12
+ {
13
+ to: "/blog",
14
+ name: "cd /posts",
15
+ },
16
+ ]}
17
+ title="history"
18
+ />
9
19
  );
10
20
  };
@@ -4,6 +4,8 @@ import { withArticleWrapper } from "@/components";
4
4
  import { MdxArticle } from "@/types/articles";
5
5
  import { Article, NotFound } from "@bbki.ng/components";
6
6
  import { useParams } from "react-router-dom";
7
+ import { usePosts } from "@/hooks/use_posts";
8
+ import { ArticlePage } from "@/components/article";
7
9
 
8
10
  type TArticleMap = {
9
11
  [key: string]: ReactElement;
@@ -19,8 +21,23 @@ MdxArticleList.forEach((article: unknown) => {
19
21
 
20
22
  export default () => {
21
23
  const { title } = useParams();
22
- if (!title || !ArticleMap[title]) {
24
+ const { posts, isError, isLoading } = usePosts(title);
25
+
26
+ if (!title) {
23
27
  return <NotFound />;
24
28
  }
25
- return ArticleMap[title];
29
+
30
+ if (ArticleMap[title]) {
31
+ return ArticleMap[title];
32
+ }
33
+
34
+ if (isError) {
35
+ return <NotFound />;
36
+ }
37
+
38
+ if (isLoading) {
39
+ return null;
40
+ }
41
+
42
+ return <ArticlePage title={title}>{posts.content}</ArticlePage>;
26
43
  };
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
2
  import { ArticleList } from "./consts";
3
- // import Tags from "@/pages/tags";
4
3
  import { LinkList, LinkProps } from "@bbki.ng/components";
5
4
  import { useRouteName } from "@/hooks";
5
+ import { usePosts } from "@/hooks/use_posts";
6
6
 
7
7
  type TxtProps = {
8
8
  title?: string;
@@ -11,11 +11,12 @@ type TxtProps = {
11
11
 
12
12
  export default (props: TxtProps) => {
13
13
  const name = useRouteName();
14
+ const { titleList, isLoading, isError } = usePosts();
15
+
16
+ const links =
17
+ isError || isLoading ? ArticleList : [...ArticleList, ...titleList];
18
+
14
19
  return (
15
- <LinkList
16
- links={props.articleList || ArticleList}
17
- title={props.title || name}
18
- // description={<Tags inline className="ml-0" withAll />}
19
- />
20
+ <LinkList links={props.articleList || links} title={props.title || name} />
20
21
  );
21
22
  };