From 3a1c406da4741b3622eb7884e6eda7dab9b1f1f7 Mon Sep 17 00:00:00 2001 From: sunface Date: Mon, 8 Feb 2021 12:02:13 +0800 Subject: [PATCH] upate --- config.yaml | 4 +- go.mod | 1 + go.sum | 2 + layouts/editor-nav.tsx | 123 ++++++++++++++++++ layouts/nav/nav.tsx | 22 +--- layouts/page-container.tsx | 5 +- next-redirect.js | 2 +- package.json | 4 + pages/[username]/[post_slug].tsx | 26 ++++ pages/[username]/index.tsx | 26 ++++ pages/editor/post/[id].tsx | 83 ++++++++++++ pages/editor/{articles.tsx => posts.tsx} | 67 ++++++---- server/internal/api/article.go | 1 + server/internal/api/editor.go | 76 +++++++++-- server/internal/posts/article.go | 113 ++++++++++++---- server/internal/server.go | 12 +- server/internal/storage/sql_tables.go | 13 +- server/internal/ui_config.go | 6 +- server/pkg/common/resp.go | 4 +- server/pkg/config/config.go | 3 +- server/pkg/e/err_code.go | 23 ++++ server/pkg/errcode/err_code.go | 7 - server/pkg/models/post.go | 28 ++-- server/pkg/models/user.go | 2 +- server/pkg/utils/compress.go | 12 ++ src/components/articles/text-article-card.tsx | 37 ------ src/components/markdown-editor/editor.tsx | 45 +++++++ src/components/markdown-editor/render.tsx | 26 ++++ src/components/posts/text-post-card.tsx | 35 +++++ src/components/radio-card.tsx | 35 +++++ src/data/editor-links.tsx | 2 +- src/types/editor.ts | 4 + src/types/posts.ts | 11 +- src/utils/config.ts | 3 +- theme.ts | 18 +-- theme/layer-styles.js | 15 +++ theme/react-markdown-editor.js | 34 +++++ theme/user-custom.js | 10 ++ yarn.lock | 24 +++- 39 files changed, 785 insertions(+), 179 deletions(-) create mode 100644 layouts/editor-nav.tsx create mode 100644 pages/[username]/[post_slug].tsx create mode 100644 pages/[username]/index.tsx create mode 100644 pages/editor/post/[id].tsx rename pages/editor/{articles.tsx => posts.tsx} (75%) create mode 100644 server/internal/api/article.go create mode 100644 server/pkg/e/err_code.go delete mode 100644 server/pkg/errcode/err_code.go create mode 100644 server/pkg/utils/compress.go delete mode 100644 src/components/articles/text-article-card.tsx create mode 100644 src/components/markdown-editor/editor.tsx create mode 100644 src/components/markdown-editor/render.tsx create mode 100644 src/components/posts/text-post-card.tsx create mode 100644 src/components/radio-card.tsx create mode 100644 src/types/editor.ts create mode 100644 theme/layer-styles.js create mode 100644 theme/react-markdown-editor.js create mode 100644 theme/user-custom.js diff --git a/config.yaml b/config.yaml index 8bf8ac59..62bf1219 100644 --- a/config.yaml +++ b/config.yaml @@ -26,4 +26,6 @@ paths: #################################### Posts ############################## posts: - brief_max_len: 100 \ No newline at end of file + brief_max_len: 100 + # whether allow writing posts + writing_enabled: true \ No newline at end of file diff --git a/go.mod b/go.mod index f7b47eec..e0574cf1 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef github.com/gin-gonic/gin v1.6.3 github.com/go-stack/stack v1.8.0 + github.com/golang/snappy v0.0.2 github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac github.com/karrick/godirwalk v1.16.1 // indirect github.com/keegancsmith/rpc v1.3.0 // indirect diff --git a/go.sum b/go.sum index 0bc7ed37..7a956b62 100644 --- a/go.sum +++ b/go.sum @@ -73,6 +73,8 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw= +github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= diff --git a/layouts/editor-nav.tsx b/layouts/editor-nav.tsx new file mode 100644 index 00000000..5a5c8ae7 --- /dev/null +++ b/layouts/editor-nav.tsx @@ -0,0 +1,123 @@ +import { + chakra, + Flex, + Button, + IconButton, + useColorMode, + useColorModeValue, + Box, + useRadioGroup, + HStack, + Input +} from "@chakra-ui/react" +import { useViewportScroll } from "framer-motion" +import NextLink from "next/link" +import React from "react" +import { FaMoon, FaSun } from "react-icons/fa" +import Logo, { LogoIcon } from "src/components/logo" +import RadioCard from "components/radio-card" +import { EditMode } from "src/types/editor" + + + + +function HeaderContent(props:any) { + const { toggleColorMode: toggleMode } = useColorMode() + const text = useColorModeValue("dark", "light") + const SwitchIcon = useColorModeValue(FaMoon, FaSun) + + const editOptions = [EditMode.Edit,EditMode.Preview] + const { getRootProps, getRadioProps } = useRadioGroup({ + name: "framework", + defaultValue: EditMode.Edit, + onChange: (v) => { + props.changeEditMode(v) + }, + }) + const group = getRootProps() + + + return ( + <> + + + + + + + + + + + + + + + + + + {editOptions.map((value) => { + const radio = getRadioProps({ value }) + return ( + + {value} + + ) + })} + + + } + /> + + + + + ) +} + +function EditorNav(props) { + const bg = useColorModeValue("white", "gray.800") + const ref = React.useRef() + const [y, setY] = React.useState(0) + const { height = 0 } = ref.current?.getBoundingClientRect() ?? {} + + const { scrollY } = useViewportScroll() + React.useEffect(() => { + return scrollY.onChange(() => setY(scrollY.get())) + }, [scrollY]) + + return ( + height ? "sm" : undefined} + transition="box-shadow 0.2s" + pos="fixed" + top="0" + zIndex="3" + bg={bg} + left="0" + right="0" + borderTop="4px solid" + borderTopColor="teal.400" + width="full" + > + + + + + ) +} + +export default EditorNav + diff --git a/layouts/nav/nav.tsx b/layouts/nav/nav.tsx index 391e9459..6c8606fa 100644 --- a/layouts/nav/nav.tsx +++ b/layouts/nav/nav.tsx @@ -3,7 +3,6 @@ import { Flex, Button, HStack, - Icon, IconButton, Link, useColorMode, @@ -16,14 +15,6 @@ import { MenuItem, MenuDivider, Image, - Modal, - ModalOverlay, - ModalContent, - ModalBody, - ModalCloseButton, - Text, - Box, - VStack, } from "@chakra-ui/react" import siteConfig from "configs/site-config" import { useViewportScroll } from "framer-motion" @@ -66,7 +57,7 @@ const GithubIcon = (props) => ( function HeaderContent() { const router = useRouter() - const { pathname } = router + const { asPath } = router const mobileNav = useDisclosure() const session: Session = useSession() @@ -81,7 +72,8 @@ function HeaderContent() { }, [mobileNav.isOpen]) const login = () => { - storage.set("current-page", pathname) + console.log(router) + storage.set("current-page", asPath) router.push('/login') } @@ -101,7 +93,7 @@ function HeaderContent() { - {navLinks.map(link => {link.title})} + {navLinks.map(link => {link.title})} @@ -109,7 +101,7 @@ function HeaderContent() { w="100%" maxW="600px" align="center" - color="gray.400" + color={useColorModeValue("gray.500","gray.400")} > @@ -151,7 +143,7 @@ function HeaderContent() { boxSize="2.8em" borderRadius="full" src="https://placekitten.com/100/100" - alt="Fluffybuns the destroyer" + alt="user" /> : } @@ -163,7 +155,7 @@ function HeaderContent() { Sunface - {} href="/editor">编辑中心} + {} href="/editor">创作中心} }>书签收藏 }>偏好设置 diff --git a/layouts/page-container.tsx b/layouts/page-container.tsx index 71697204..f7a289cc 100644 --- a/layouts/page-container.tsx +++ b/layouts/page-container.tsx @@ -26,10 +26,11 @@ function useHeadingFocusOnRouteChange() { interface PageContainerProps { children: React.ReactNode + nav?: any } function PageContainer(props: PageContainerProps) { - const { children } = props + const { children ,nav} = props useHeadingFocusOnRouteChange() return ( @@ -39,7 +40,7 @@ function PageContainer(props: PageContainerProps) { description={siteConfig.seo.description} /> Skip to Content -