├── .husky ├── _ │ ├── .gitignore │ └── husky.sh └── pre-commit ├── public ├── close.png ├── code.png ├── favicon.ico ├── logo_dark.png ├── logo_light.png ├── theme_dark.png ├── close_light.png ├── home_bg_dark.png ├── public_logo.png ├── theme_light.png ├── home_bg_dark.webp ├── home_bg_light.png └── home_bg_light.webp ├── .eslintrc.json ├── components ├── layout │ ├── styles.module.scss │ └── index.tsx ├── navbar │ ├── styles.module.scss │ └── index.tsx ├── popup │ ├── index.tsx │ └── styles.module.scss └── footer │ ├── index.tsx │ └── styles.module.scss ├── commitlint.config.js ├── next-env.d.ts ├── constants └── enum.ts ├── README.md ├── next.config.js ├── .gitignore ├── pages ├── api │ ├── articleInfo.ts │ ├── home.ts │ ├── articleIntro.ts │ └── layout.ts ├── media.scss ├── _document.tsx ├── article │ ├── styles.module.scss │ └── [articleId].tsx ├── _app.tsx ├── global.scss ├── index.tsx └── index.module.scss ├── utils └── index.ts ├── tsconfig.json ├── package.json └── stores ├── language.tsx ├── theme.tsx └── userAgent.tsx /.husky/_/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/close.png -------------------------------------------------------------------------------- /public/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/code.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/logo_dark.png -------------------------------------------------------------------------------- /public/logo_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/logo_light.png -------------------------------------------------------------------------------- /public/theme_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/theme_dark.png -------------------------------------------------------------------------------- /public/close_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/close_light.png -------------------------------------------------------------------------------- /public/home_bg_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/home_bg_dark.png -------------------------------------------------------------------------------- /public/public_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/public_logo.png -------------------------------------------------------------------------------- /public/theme_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/theme_light.png -------------------------------------------------------------------------------- /public/home_bg_dark.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/home_bg_dark.webp -------------------------------------------------------------------------------- /public/home_bg_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/home_bg_light.png -------------------------------------------------------------------------------- /public/home_bg_light.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/czm1290433700/nextjs-demo/HEAD/public/home_bg_light.webp -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals", 3 | "rules": { 4 | "react/display-name": "off" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npm run lint 5 | npx commitlint --edit $1 6 | -------------------------------------------------------------------------------- /components/layout/styles.module.scss: -------------------------------------------------------------------------------- 1 | .layout { 2 | background-color: var(--primary-background-color); 3 | .main { 4 | min-height: calc(100vh - 34.85rem); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["@commitlint/config-conventional"], 3 | rules: { 4 | "type-enum": [2, "always", ["feat", "fix", "revert"]], 5 | "subject-max-length": [1, "always", 30], 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /constants/enum.ts: -------------------------------------------------------------------------------- 1 | export enum Themes { 2 | light = "light", 3 | dark = "dark", 4 | } 5 | 6 | export enum Environment { 7 | pc = "pc", 8 | ipad = "ipad", 9 | mobile = "mobile", 10 | none = "none", 11 | } 12 | 13 | export enum Language { 14 | ch = "ch", 15 | en = "en", 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Demo for 《SSR 实战:官网开发指南》 2 | 3 | 《SSR 实战:官网开发指南》实战篇 教学代码 4 | 5 | ## 项目启动 6 | 7 | 1. fork cms 数据层仓库 https://github.com/czm1290433700/nextjs-cms 参照对应 readme 启动 8 | 2. nextjs-demo 启动 9 | 10 | ``` 11 | npm install 12 | npm run dev 13 | ``` 14 | 15 | ## 项目调试 16 | 17 | ``` 18 | npm run debugger 19 | ``` 20 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | const semi = require("@douyinfe/semi-next").default({}); 4 | 5 | module.exports = semi({ 6 | reactStrictMode: true, 7 | swcMinify: true, 8 | webpack: (config) => { 9 | config.resolve.alias = { 10 | ...config.resolve.alias, 11 | "@": path.resolve(__dirname), 12 | }; 13 | return config; 14 | }, 15 | images: { 16 | domains: ["127.0.0.1"], 17 | }, 18 | }); 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | .pnpm-debug.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | -------------------------------------------------------------------------------- /pages/api/articleInfo.ts: -------------------------------------------------------------------------------- 1 | import type { NextApiRequest, NextApiResponse } from 'next'; 2 | import axios from 'axios'; 3 | import { CMSDOMAIN } from '@/utils'; 4 | import { IArticleProps } from '../article/[articleId]'; 5 | 6 | const getArticleInfoData = (req: NextApiRequest, res: NextApiResponse): void => { 7 | const { articleId } = req.query; 8 | axios.get(`${CMSDOMAIN}/api/article-infos/${articleId}`).then(result => { 9 | const data = result.data || {}; 10 | res.status(200).json(data); 11 | }); 12 | }; 13 | 14 | export default getArticleInfoData; 15 | -------------------------------------------------------------------------------- /utils/index.ts: -------------------------------------------------------------------------------- 1 | import { AppContext } from "next/app"; 2 | 3 | export const LOCALDOMAIN = "http://127.0.0.1:3000"; 4 | export const CMSDOMAIN = "http://127.0.0.1:1337"; 5 | 6 | export const getIsMobile = (context: AppContext) => { 7 | const { headers = {} } = context.ctx.req || {}; 8 | return /mobile|android|iphone|ipad|phone/i.test( 9 | (headers["user-agent"] || "").toLowerCase() 10 | ); 11 | }; 12 | 13 | export const getIsSupportWebp = (context: AppContext) => { 14 | const { headers = {} } = context.ctx.req || {}; 15 | return headers.accept?.includes("image/webp"); 16 | }; 17 | -------------------------------------------------------------------------------- /pages/api/home.ts: -------------------------------------------------------------------------------- 1 | import type { NextApiRequest, NextApiResponse } from 'next'; 2 | import axios from 'axios'; 3 | import { CMSDOMAIN } from '@/utils'; 4 | 5 | interface IHomeProps { 6 | title: string; 7 | description: string; 8 | } 9 | 10 | const getHomeData = (req: NextApiRequest, res: NextApiResponse): void => { 11 | axios.get(`${CMSDOMAIN}/api/homes`).then(result => { 12 | const { title, description } = result.data || {}; 13 | 14 | res.status(200).json({ 15 | title, 16 | description, 17 | }); 18 | }); 19 | }; 20 | 21 | export default getHomeData; 22 | -------------------------------------------------------------------------------- /pages/media.scss: -------------------------------------------------------------------------------- 1 | // 极小分辨率移动端设备 2 | @mixin media-mini-mobile { 3 | @media screen and (max-width: 25.875rem) { 4 | @content; 5 | } 6 | } 7 | 8 | // 介于极小分辨率和正常分辨率之间的移动端设备 9 | @mixin media-between-mini-and-normal-mobile { 10 | @media screen and (min-width: 25.876rem) and (max-width: 47.9375rem) { 11 | @content; 12 | } 13 | } 14 | 15 | // 移动端设备 16 | @mixin media-mobile { 17 | @media screen and (max-width: 47.9375rem) { 18 | @content; 19 | } 20 | } 21 | 22 | // ipad 23 | @mixin media-ipad { 24 | @media screen and (min-width: 47.9375rem) and (max-width: 75rem) { 25 | @content; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pages/_document.tsx: -------------------------------------------------------------------------------- 1 | import { Html, Head, Main, NextScript } from 'next/document'; 2 | import Script from 'next/script'; 3 | import React from 'react'; 4 | 5 | export default function Document(): JSX.Element { 6 | return ( 7 | 8 | 9 | 10 |
11 | 12 | 17 | 18 | 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /components/layout/index.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from "react"; 2 | import { IFooterProps, Footer } from "../footer/index"; 3 | import { INavBarProps, NavBar } from "../navbar/index"; 4 | import styles from "./styles.module.scss"; 5 | 6 | export interface ILayoutProps { 7 | navbarData: INavBarProps; 8 | footerData: IFooterProps; 9 | } 10 | 11 | export const Layout: FC = ({ 12 | navbarData, 13 | footerData, 14 | children, 15 | }) => { 16 | return ( 17 |
18 | 19 |
{children}
20 |
21 |
22 | ); 23 | }; 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true, 17 | "baseUrl": "./", 18 | "paths": { 19 | "@/*": ["./*"] 20 | }, 21 | "plugins": [{ "name": "typescript-plugin-css-modules" }] 22 | }, 23 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 24 | "exclude": ["node_modules"] 25 | } 26 | -------------------------------------------------------------------------------- /.husky/_/husky.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | if [ -z "$husky_skip_init" ]; then 3 | debug () { 4 | if [ "$HUSKY_DEBUG" = "1" ]; then 5 | echo "husky (debug) - $1" 6 | fi 7 | } 8 | 9 | readonly hook_name="$(basename -- "$0")" 10 | debug "starting $hook_name..." 11 | 12 | if [ "$HUSKY" = "0" ]; then 13 | debug "HUSKY env variable is set to 0, skipping hook" 14 | exit 0 15 | fi 16 | 17 | if [ -f ~/.huskyrc ]; then 18 | debug "sourcing ~/.huskyrc" 19 | . ~/.huskyrc 20 | fi 21 | 22 | readonly husky_skip_init=1 23 | export husky_skip_init 24 | sh -e "$0" "$@" 25 | exitCode="$?" 26 | 27 | if [ $exitCode != 0 ]; then 28 | echo "husky - $hook_name hook exited with code $exitCode (error)" 29 | fi 30 | 31 | if [ $exitCode = 127 ]; then 32 | echo "husky - command not found in PATH=$PATH" 33 | fi 34 | 35 | exit $exitCode 36 | fi 37 | -------------------------------------------------------------------------------- /pages/api/articleIntro.ts: -------------------------------------------------------------------------------- 1 | import type { NextApiRequest, NextApiResponse } from 'next'; 2 | import axios from 'axios'; 3 | import { CMSDOMAIN } from '@/utils'; 4 | 5 | export interface IArticleIntro { 6 | label: string; 7 | info: string; 8 | articleId: number; 9 | } 10 | 11 | interface IArticleIntroProps { 12 | list: Array<{ label: string; info: string; articleId: number }>; 13 | total: number; 14 | } 15 | 16 | const getArticleIntroData = (req: NextApiRequest, res: NextApiResponse): void => { 17 | const { pageNo, pageSize } = req.body; 18 | axios 19 | .get(`${CMSDOMAIN}/api/article-introductions`, { 20 | params: { 21 | pageNo, 22 | pageSize, 23 | }, 24 | }) 25 | .then(result => { 26 | const { data, meta } = result.data || {}; 27 | 28 | res.status(200).json({ 29 | list: Object.values(data), 30 | total: meta.pagination.total, 31 | }); 32 | }); 33 | }; 34 | 35 | export default getArticleIntroData; 36 | -------------------------------------------------------------------------------- /components/navbar/styles.module.scss: -------------------------------------------------------------------------------- 1 | .navBar { 2 | display: flex; 3 | align-items: center; 4 | justify-content: space-between; 5 | background-color: var(--navbar-background-color); 6 | backdrop-filter: blur(0.5rem); 7 | width: 100%; 8 | height: 4rem; 9 | position: sticky; 10 | top: 0; 11 | left: 0; 12 | padding: 1.25rem 2rem; 13 | z-index: 100; 14 | box-sizing: border-box; 15 | 16 | .logoIcon { 17 | width: 4.375rem; 18 | height: 1.25rem; 19 | background-image: var(--navbar-icon); 20 | background-size: 4.375rem 1.25rem; 21 | background-repeat: no-repeat; 22 | } 23 | 24 | .themeArea { 25 | display: flex; 26 | align-items: center; 27 | color: var(--primary-color); 28 | font-size: 0.875rem; 29 | 30 | .popupText { 31 | margin-right: 1rem; 32 | cursor: pointer; 33 | } 34 | 35 | .text { 36 | margin-right: 1rem; 37 | } 38 | 39 | .themeIcon { 40 | width: 1.25rem; 41 | height: 1.25rem; 42 | background-image: var(--theme-icon); 43 | background-size: 1.25rem 1.25rem; 44 | background-repeat: no-repeat; 45 | cursor: pointer; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nextjs-demo", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "debugger": "cross-env NODE_OPTIONS='--inspect' next dev", 8 | "build": "next build", 9 | "start": "next start", 10 | "lint": "next lint" 11 | }, 12 | "dependencies": { 13 | "@douyinfe/semi-next": "^2.17.1", 14 | "@douyinfe/semi-ui": "^2.17.1", 15 | "axios": "^0.27.2", 16 | "classnames": "^2.3.1", 17 | "lodash": "^4.17.21", 18 | "next": "^12.2.4-canary.9", 19 | "next-connect": "^0.13.0", 20 | "react": "^18.2.0", 21 | "react-dom": "^18.2.0", 22 | "showdown": "^2.1.0" 23 | }, 24 | "devDependencies": { 25 | "@commitlint/cli": "^17.0.3", 26 | "@commitlint/config-conventional": "^17.0.3", 27 | "@types/lodash": "^4.14.182", 28 | "@types/node": "18.6.1", 29 | "@types/react": "18.0.15", 30 | "@types/react-dom": "18.0.6", 31 | "cross-env": "^7.0.3", 32 | "eslint": "8.20.0", 33 | "eslint-config-next": "12.2.3", 34 | "husky": "^8.0.1", 35 | "sass": "^1.54.0", 36 | "typescript": "4.7.4", 37 | "typescript-plugin-css-modules": "^3.4.0" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pages/api/layout.ts: -------------------------------------------------------------------------------- 1 | import type { NextApiRequest, NextApiResponse } from 'next'; 2 | import axios from 'axios'; 3 | import { ILayoutProps } from '../../components/layout'; 4 | import { CMSDOMAIN } from '@/utils'; 5 | import { isEmpty } from 'lodash'; 6 | 7 | const getLayoutData = (req: NextApiRequest, res: NextApiResponse): void => { 8 | axios.get(`${CMSDOMAIN}/api/layouts`).then(result => { 9 | const { copy_right, link_lists, public_number, qr_code, qr_code_image, site_number, title } = result.data || {}; 10 | 11 | res.status(200).json({ 12 | navbarData: {}, 13 | footerData: { 14 | title, 15 | linkList: link_lists?.data?.map((item: any) => ({ 16 | title: item.title, 17 | list: item?.links?.data?.map((_item: any) => ({ 18 | label: _item.label, 19 | link: isEmpty(_item.link) ? '' : _item.link, 20 | })), 21 | })), 22 | qrCode: { 23 | image: `${CMSDOMAIN}${qr_code_image.data.url}`, 24 | text: qr_code, 25 | }, 26 | copyRight: copy_right, 27 | siteNumber: site_number, 28 | publicNumber: public_number, 29 | }, 30 | }); 31 | }); 32 | }; 33 | 34 | export default getLayoutData; 35 | -------------------------------------------------------------------------------- /stores/language.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, createContext } from 'react'; 2 | import { Language } from '@/constants/enum'; 3 | 4 | interface ILanguageContextProps { 5 | language: Language; 6 | setLanguage: (language: Language) => void; 7 | } 8 | 9 | interface IProps { 10 | children: JSX.Element; 11 | } 12 | 13 | export const LanguageContext = createContext({} as ILanguageContextProps); 14 | 15 | export const LanguageContextProvider = ({ children }: IProps): JSX.Element => { 16 | const [language, setLanguage] = useState(Language.ch); 17 | 18 | useEffect(() => { 19 | const checkLanguage = (): void => { 20 | const item = (localStorage.getItem('language') as Language) || Language.ch; 21 | setLanguage(item); 22 | }; 23 | checkLanguage(); 24 | window.addEventListener('storage', checkLanguage); 25 | return (): void => { 26 | window.removeEventListener('storage', checkLanguage); 27 | }; 28 | }, []); 29 | 30 | return ( 31 | { 35 | setLanguage(currentLanguage); 36 | localStorage.setItem('language', currentLanguage); 37 | }, 38 | }} 39 | > 40 | {children} 41 | 42 | ); 43 | }; 44 | -------------------------------------------------------------------------------- /stores/theme.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, createContext } from 'react'; 2 | import { Themes } from '@/constants/enum'; 3 | 4 | interface IThemeContextProps { 5 | theme: Themes; 6 | setTheme: (theme: Themes) => void; 7 | } 8 | 9 | interface IProps { 10 | children: JSX.Element; 11 | } 12 | 13 | export const ThemeContext = createContext({} as IThemeContextProps); 14 | 15 | export const ThemeContextProvider = ({ children }: IProps): JSX.Element => { 16 | const [theme, setTheme] = useState(Themes.light); 17 | 18 | // 监听本地缓存来同步不同页面间的主题 19 | useEffect(() => { 20 | const checkTheme = (): void => { 21 | const item = (localStorage.getItem('theme') as Themes) || Themes.light; 22 | setTheme(item); 23 | document.getElementsByTagName('html')[0].dataset.theme = item; 24 | }; 25 | checkTheme(); 26 | window.addEventListener('storage', checkTheme); 27 | return (): void => { 28 | window.removeEventListener('storage', checkTheme); 29 | }; 30 | }, []); 31 | 32 | return ( 33 | { 37 | setTheme(currentTheme); 38 | localStorage.setItem('theme', currentTheme); 39 | document.getElementsByTagName('html')[0].dataset.theme = currentTheme; 40 | }, 41 | }} 42 | > 43 | {children} 44 | 45 | ); 46 | }; 47 | -------------------------------------------------------------------------------- /pages/article/styles.module.scss: -------------------------------------------------------------------------------- 1 | @import "../media.scss"; 2 | 3 | .article { 4 | color: var(--primary-color); 5 | width: 50rem; 6 | margin: auto; 7 | 8 | .title { 9 | margin-bottom: 1rem; 10 | } 11 | 12 | .info { 13 | font-size: 0.875rem; 14 | line-height: 1.25rem; 15 | color: var(--secondary-color); 16 | opacity: 0.6; 17 | margin-bottom: 2.5rem; 18 | } 19 | 20 | .description { 21 | font-size: 0.875rem; 22 | line-height: 1.25rem; 23 | color: var(--secondary-color); 24 | padding-left: 1.25rem; 25 | margin-bottom: 2.5rem; 26 | position: relative; 27 | } 28 | 29 | .description::before { 30 | content: ""; 31 | width: 0.25rem; 32 | height: 1.25rem; 33 | background-color: var(--secondary-color); 34 | opacity: 0.2; 35 | position: absolute; 36 | left: 0; 37 | bottom: -0.125rem; 38 | } 39 | 40 | .content { 41 | margin-bottom: 5rem; 42 | font-size: 16px; 43 | line-height: 32px; 44 | 45 | img { 46 | width: 50rem; 47 | } 48 | } 49 | } 50 | 51 | @include media-ipad { 52 | .article { 53 | width: 80%; 54 | .content { 55 | img { 56 | width: 100%; 57 | } 58 | } 59 | } 60 | } 61 | 62 | @include media-mobile { 63 | .article { 64 | width: 80%; 65 | .title { 66 | font-size: 1.75rem; 67 | line-height: 2.4375rem; 68 | } 69 | .content { 70 | h2 { 71 | font-size: 1.125rem; 72 | line-height: 1.5625rem; 73 | } 74 | img { 75 | width: 100%; 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /stores/userAgent.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, createContext } from 'react'; 2 | import { Environment } from '@/constants/enum'; 3 | 4 | interface IUserAgentContextProps { 5 | userAgent: Environment; 6 | } 7 | 8 | interface IProps { 9 | children: JSX.Element; 10 | } 11 | 12 | export const UserAgentContext = createContext({} as IUserAgentContextProps); 13 | 14 | export const UserAgentProvider = ({ children }: IProps): JSX.Element => { 15 | const [userAgent, setUserAgent] = useState(Environment.none); // 服务器渲染初始化渲染未必是预期效果,none缓冲切换视觉) 16 | 17 | // 监听本地缓存来同步不同页面间的主题(当前页面无法监听到,直接在顶部栏进行了类的切换) 18 | useEffect(() => { 19 | const checkUserAgent = (): void => { 20 | const width = document.body.offsetWidth; 21 | // 用宽度去判断,是为了适配不改机型,仅拉扯屏幕宽度的情况 22 | if (width < 768) { 23 | // 手机端 24 | setUserAgent(Environment.mobile); 25 | } else if (width >= 768 && width < 1200) { 26 | // ipad端 27 | setUserAgent(Environment.ipad); 28 | } else if (width >= 1200) { 29 | // pc端 30 | setUserAgent(Environment.pc); 31 | } else { 32 | setUserAgent(Environment.none); // 增加none类型来缓冲默认类型样式切换时的视觉突变 33 | } 34 | }; 35 | checkUserAgent(); 36 | window.addEventListener('resize', checkUserAgent); // 监听屏幕宽度变化,及时适配当前页面样式 37 | return (): void => { 38 | window.removeEventListener('resize', checkUserAgent); 39 | }; 40 | }, [typeof document !== 'undefined' && document.body.offsetWidth]); 41 | 42 | return {children}; 43 | }; 44 | -------------------------------------------------------------------------------- /components/navbar/index.tsx: -------------------------------------------------------------------------------- 1 | import { FC, useContext, useRef } from "react"; 2 | import styles from "./styles.module.scss"; 3 | import { ThemeContext } from "@/stores/theme"; 4 | import { UserAgentContext } from "@/stores/userAgent"; 5 | import { Themes, Environment } from "@/constants/enum"; 6 | import { Popup, IPopupRef } from "../popup"; 7 | 8 | export interface INavBarProps {} 9 | 10 | export const NavBar: FC = ({}) => { 11 | const { setTheme } = useContext(ThemeContext); 12 | const { userAgent } = useContext(UserAgentContext); 13 | const popupRef = useRef(null); 14 | 15 | return ( 16 |
17 | 18 |
19 |
20 |
21 |
{ 24 | popupRef.current?.open(); 25 | }} 26 | > 27 | 弹窗示范 28 |
29 | {userAgent === Environment.pc && ( 30 | 当前是pc端样式 31 | )} 32 | {userAgent === Environment.ipad && ( 33 | 当前是Ipad端样式 34 | )} 35 | {userAgent === Environment.mobile && ( 36 | 当前是移动端样式 37 | )} 38 |
{ 41 | if (localStorage.getItem("theme") === Themes.light) { 42 | setTheme(Themes.dark); 43 | } else { 44 | setTheme(Themes.light); 45 | } 46 | }} 47 | >
48 |
49 | 50 |
这是一个弹窗
51 |
52 |
53 | ); 54 | }; 55 | -------------------------------------------------------------------------------- /pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import type { AppProps, AppContext } from 'next/app'; 2 | import React from 'react'; 3 | import App from 'next/app'; 4 | import { Layout, ILayoutProps } from '@/components/layout'; 5 | import Head from 'next/head'; 6 | import axios from 'axios'; 7 | import { getIsMobile, getIsSupportWebp, LOCALDOMAIN } from '@/utils'; 8 | import { ThemeContextProvider } from '@/stores/theme'; 9 | import { UserAgentProvider } from '@/stores/userAgent'; 10 | import { LanguageContextProvider } from '@/stores/language'; 11 | import './global.scss'; 12 | export interface IComponentProps { 13 | isMobile?: boolean; 14 | isSupportWebp?: boolean; 15 | } 16 | 17 | const MyApp = (data: AppProps & ILayoutProps & IComponentProps): JSX.Element => { 18 | const { Component, pageProps, navbarData, footerData, isMobile, isSupportWebp } = data; 19 | 20 | return ( 21 |
22 | 23 | {`A Demo for 《SSR 实战:官网开发指南》(${isMobile ? '移动端' : 'pc端'})`} 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
39 | ); 40 | }; 41 | 42 | MyApp.getInitialProps = async (context: AppContext): Promise => { 43 | const pageProps = await App.getInitialProps(context); 44 | const { data = {} } = await axios.get(`${LOCALDOMAIN}/api/layout`); 45 | 46 | return { 47 | ...pageProps, 48 | ...data, 49 | isMobile: getIsMobile(context), 50 | isSupportWebp: getIsSupportWebp(context), 51 | }; 52 | }; 53 | 54 | export default MyApp; 55 | -------------------------------------------------------------------------------- /pages/article/[articleId].tsx: -------------------------------------------------------------------------------- 1 | import { LOCALDOMAIN } from '@/utils'; 2 | import axios from 'axios'; 3 | import React from 'react'; 4 | import type { GetServerSideProps, GetStaticPaths, GetStaticProps, NextPage } from 'next'; 5 | import styles from './styles.module.scss'; 6 | 7 | // eslint-disable-next-line @typescript-eslint/no-var-requires 8 | const showdown = require('showdown'); 9 | 10 | export interface IArticleProps { 11 | title: string; 12 | author: string; 13 | description: string; 14 | createTime: string; 15 | content: string; 16 | } 17 | 18 | const Article: NextPage = ({ title, author, description, createTime, content }) => { 19 | const converter = new showdown.Converter(); 20 | return ( 21 |
22 |

{title}

23 |
24 | 作者:{author} | 创建时间: {createTime} 25 |
26 |
{description}
27 |
28 |
29 | ); 30 | }; 31 | 32 | // Article.getInitialProps = async (context): Promise => { 33 | // // debugger; 34 | // const { articleId } = context.query; 35 | // const { data } = await axios.get(`${LOCALDOMAIN}/api/articleInfo`, { 36 | // params: { 37 | // articleId, 38 | // }, 39 | // }); 40 | // return data; 41 | // }; 42 | 43 | export const getServerSideProps: GetServerSideProps = async context => { 44 | const { articleId } = context.query; 45 | const { data } = await axios.get(`${LOCALDOMAIN}/api/articleInfo`, { 46 | params: { 47 | articleId, 48 | }, 49 | }); 50 | return { 51 | props: data, // 需要拿props包裹 52 | }; 53 | }; 54 | 55 | // ssg; 56 | // export const getStaticPaths: GetStaticPaths = async () => ({ 57 | // paths: [{ params: { articleId: '1' } }], 58 | // fallback: false, 59 | // }); 60 | 61 | // export const getStaticProps: GetStaticProps = async context => { 62 | // const { articleId } = context.params as any; 63 | // const { data } = await axios.get(`${LOCALDOMAIN}/api/articleInfo`, { 64 | // params: { 65 | // articleId, 66 | // }, 67 | // }); 68 | // return { 69 | // props: data, 70 | // }; 71 | // }; 72 | 73 | export default Article; 74 | -------------------------------------------------------------------------------- /components/popup/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { 2 | forwardRef, 3 | useState, 4 | useEffect, 5 | useImperativeHandle, 6 | useContext, 7 | useMemo, 8 | } from "react"; 9 | import styles from "./styles.module.scss"; 10 | import ReactDom from "react-dom"; 11 | import { UserAgentContext } from "@/stores/userAgent"; 12 | import { Environment } from "@/constants/enum"; 13 | import cName from "classnames"; 14 | 15 | export interface IPopupRef { 16 | open: () => void; 17 | } 18 | 19 | interface IProps { 20 | children: JSX.Element; 21 | } 22 | 23 | export const Popup = forwardRef(({ children }, ref) => { 24 | const [visible, setVisible] = useState(false); 25 | const [enter, setEnter] = useState(false); 26 | const [leave, setLeave] = useState(false); 27 | const { userAgent } = useContext(UserAgentContext); 28 | 29 | useEffect(() => { 30 | document.body.className = visible ? "forbidScroll" : ""; 31 | let timeout; 32 | if (visible) { 33 | setEnter(true); 34 | timeout = setTimeout((): void => { 35 | setEnter(false); 36 | }, 300); 37 | } else { 38 | setLeave(true); 39 | timeout = setTimeout((): void => { 40 | setLeave(false); 41 | }, 300); 42 | } 43 | return (): void => { 44 | timeout = null; 45 | }; 46 | }, [visible]); 47 | 48 | useImperativeHandle(ref, () => ({ 49 | open: (): void => { 50 | setEnter(true); 51 | setVisible(true); 52 | setTimeout((): void => { 53 | setEnter(false); 54 | }, 300); 55 | }, 56 | })); 57 | 58 | const renderDom = visible ? ( 59 |
66 |
67 |
68 |
{ 71 | setLeave(true); 72 | setTimeout((): void => { 73 | setLeave(false); 74 | }, 300); 75 | setVisible(false); 76 | }} 77 | /> 78 | {children} 79 |
80 |
81 | ) : ( 82 | <> 83 | ); 84 | 85 | return typeof document !== "undefined" 86 | ? ReactDom.createPortal(renderDom, document.body) 87 | : renderDom; 88 | }); 89 | -------------------------------------------------------------------------------- /pages/global.scss: -------------------------------------------------------------------------------- 1 | @import "~@douyinfe/semi-ui/dist/css/semi.min.css"; 2 | 3 | html[data-theme="dark"] { 4 | --primary-color: #ffffff; 5 | --primary-background-color: rgba(14, 14, 14, 1); 6 | --footer-background-color: rgba(36, 36, 36, 1); 7 | --navbar-background-color: rgba(0, 0, 0, 0.5); 8 | --secondary-color: rgba(255, 255, 255, 0.5); 9 | --link-color: #34a8eb; 10 | --semi-page-active-color: rgb(84, 169, 255); 11 | --semi-page-active-background-color: rgba(84, 169, 255, 0.2); 12 | --semi-page-hover-background-color: rgb(23, 23, 23); 13 | --navbar-icon: url("../public/logo_dark.png"); 14 | --theme-icon: url("../public/theme_dark.png"); 15 | --popup-close-icon: url("../public/close.png"); 16 | --popup-close-hover-background-color: #353535; 17 | --popup-content-background-color: #1f1f1f; 18 | --home-background-icon: url("../public/home_bg_dark.png"); 19 | --home-background-icon-webp: url("../public/home_bg_dark.webp"); 20 | } 21 | 22 | html[data-theme="light"] { 23 | --primary-color: #333333; 24 | --primary-background-color: rgba(255, 255, 255, 1); 25 | --footer-background-color: #f4f5f5; 26 | --navbar-background-color: rgba(255, 255, 255, 0.5); 27 | --secondary-color: #666666; 28 | --link-color: #0070f3; 29 | --semi-page-active-color: #333333; 30 | --semi-page-active-background-color: rgb(234, 245, 255); 31 | --semi-page-hover-background-color: rgb(244, 245, 245); 32 | --navbar-icon: url("../public/logo_light.png"); 33 | --theme-icon: url("../public/theme_light.png"); 34 | --popup-close-icon: url("../public/close_light.png"); 35 | --popup-close-hover-background-color: #f5f5f5; 36 | --popup-content-background-color: #f4f5f5; 37 | --home-background-icon: url("../public/home_bg_light.png"); 38 | --home-background-icon-webp: url("../public/home_bg_light.webp"); 39 | } 40 | 41 | html, 42 | body { 43 | font-size: 16px; 44 | padding: 0; 45 | margin: 0; 46 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, 47 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 48 | color: var(--primary-color); 49 | overflow: hidden; 50 | } 51 | 52 | a { 53 | color: inherit; 54 | text-decoration: none; 55 | } 56 | 57 | * { 58 | box-sizing: border-box; 59 | } 60 | 61 | .forbidScroll { 62 | height: 100vh; 63 | overflow: hidden; 64 | } 65 | 66 | #__next { 67 | height: 100vh; 68 | overflow: auto; 69 | } 70 | -------------------------------------------------------------------------------- /components/popup/styles.module.scss: -------------------------------------------------------------------------------- 1 | @import "../../pages/media.scss"; 2 | 3 | .popup { 4 | width: 100%; 5 | height: 100vh; 6 | display: flex; 7 | justify-content: center; 8 | align-items: center; 9 | position: fixed; 10 | top: 0; 11 | left: 0; 12 | z-index: 10000; 13 | 14 | .mask { 15 | width: inherit; 16 | height: inherit; 17 | position: fixed; 18 | background-color: #000; 19 | opacity: 0.5; 20 | top: 0; 21 | left: 0; 22 | z-index: 10; 23 | } 24 | 25 | .popupContent { 26 | position: relative; 27 | border-radius: 0.25rem; 28 | display: flex; 29 | flex-direction: column; 30 | align-items: center; 31 | justify-content: center; 32 | background-color: var(--popup-content-background-color); 33 | z-index: 20; 34 | min-width: 25rem; 35 | min-height: 25rem; 36 | 37 | .closeBtn { 38 | width: 2.125rem; 39 | height: 2.125rem; 40 | background-color: inherit; 41 | background-image: var(--popup-close-icon); 42 | background-position: center; 43 | background-size: 1rem 1rem; 44 | background-repeat: no-repeat; 45 | position: absolute; 46 | top: 1.1875rem; 47 | right: 1.1875rem; 48 | cursor: pointer; 49 | z-index: 100; 50 | } 51 | 52 | .closeBtn:hover { 53 | background-color: var(--popup-close-hover-background-color); 54 | } 55 | } 56 | } 57 | 58 | .enter { 59 | .mask { 60 | animation: maskFadeIn 0.2s; 61 | } 62 | 63 | .popupContent { 64 | animation: fadeIn 0.2s; 65 | } 66 | } 67 | 68 | .leave { 69 | .mask { 70 | animation: maskFadeOut 0.2s; 71 | opacity: 0; 72 | } 73 | 74 | .popupContent { 75 | animation: fadeOut 0.2s; 76 | transform: scale(0); 77 | } 78 | } 79 | 80 | @keyframes fadeIn { 81 | 0% { 82 | transform: scale(0); 83 | opacity: 0; 84 | } 85 | 86 | 100% { 87 | transform: scale(1); 88 | opacity: 1; 89 | } 90 | } 91 | 92 | @keyframes fadeOut { 93 | 0% { 94 | transform: scale(1); 95 | opacity: 1; 96 | } 97 | 98 | 100% { 99 | transform: scale(0); 100 | opacity: 0; 101 | } 102 | } 103 | 104 | @keyframes maskFadeIn { 105 | 0% { 106 | opacity: 0; 107 | } 108 | 109 | 100% { 110 | opacity: 0.5; 111 | } 112 | } 113 | 114 | @keyframes maskFadeOut { 115 | 0% { 116 | opacity: 0.5; 117 | } 118 | 119 | 100% { 120 | opacity: 0; 121 | } 122 | } 123 | 124 | @include media-mobile { 125 | .popup { 126 | .popupContent { 127 | min-width: 18.75rem; 128 | min-height: 18.75rem; 129 | .closeBtn { 130 | width: 0.6875rem; 131 | height: 0.6875rem; 132 | top: 1.3125rem; 133 | right: 0.875rem; 134 | } 135 | } 136 | } 137 | } 138 | 139 | @include media-ipad { 140 | .popup { 141 | .popupContent { 142 | .titleArea { 143 | padding: 1.5rem 1.5625rem; 144 | } 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /components/footer/index.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from "react"; 2 | import Image from "next/image"; 3 | import publicLogo from "@/public/public_logo.png"; 4 | import styles from "./styles.module.scss"; 5 | import cName from "classnames"; 6 | 7 | interface ILink { 8 | label: string; 9 | link?: string; 10 | } 11 | 12 | interface ILinkList { 13 | title: string; 14 | list: ILink[]; 15 | } 16 | 17 | interface IQRCode { 18 | image: string; 19 | text: string; 20 | } 21 | 22 | export interface IFooterProps { 23 | title: string; 24 | linkList: ILinkList[]; 25 | qrCode: IQRCode; 26 | copyRight: string; 27 | siteNumber: string; // 站点备案号 28 | publicNumber: string; // 公安备案号 29 | } 30 | 31 | export const Footer: FC = ({ 32 | title, 33 | linkList, 34 | qrCode, 35 | copyRight, 36 | siteNumber, 37 | publicNumber, 38 | }) => { 39 | return ( 40 |
41 |
42 |

{title}

43 |
44 | {linkList?.map((item, index) => { 45 | return ( 46 |
47 | {item.title} 48 |
49 | {item.list?.map((_item, _index) => { 50 | return ( 51 |
{ 57 | _item.link && 58 | window.open( 59 | _item.link, 60 | "blank", 61 | "noopener=yes,noreferrer=yes" 62 | ); 63 | }} 64 | key={`link${_index}`} 65 | > 66 | {_item.label} 67 |
68 | ); 69 | })} 70 |
71 |
72 | ); 73 | })} 74 |
75 |
76 |
77 |
78 |
79 | {qrCode?.text} 85 |
86 |
{qrCode?.text}
87 |
88 |
89 | {copyRight} 90 | {siteNumber} 91 |
92 |
93 | {publicNumber} 99 |
100 | {publicNumber} 101 |
102 |
103 |
104 |
105 | ); 106 | }; 107 | -------------------------------------------------------------------------------- /components/footer/styles.module.scss: -------------------------------------------------------------------------------- 1 | @import "../../pages/media.scss"; 2 | 3 | .footer { 4 | font-size: 1rem; 5 | padding: 4.375rem 9.0625rem; 6 | background-color: var(--footer-background-color); 7 | .topArea { 8 | display: flex; 9 | justify-content: space-between; 10 | flex-wrap: wrap; 11 | 12 | .footerTitle { 13 | font-weight: 500; 14 | font-size: 2.25rem; 15 | line-height: 2.25rem; 16 | color: var(--primary-color); 17 | margin: 0; 18 | } 19 | 20 | .linkListArea { 21 | display: flex; 22 | .linkArea { 23 | display: flex; 24 | flex-direction: column; 25 | margin-left: 10rem; 26 | .title { 27 | font-weight: 500; 28 | font-size: 0.875rem; 29 | line-height: 1.25rem; 30 | color: var(--primary-color); 31 | margin-bottom: 2.5rem; 32 | word-break: keep-all; 33 | } 34 | 35 | .links { 36 | display: flex; 37 | flex-direction: column; 38 | font-weight: 400; 39 | font-size: 0.875rem; 40 | line-height: 1.25rem; 41 | word-break: keep-all; 42 | 43 | .link { 44 | color: var(--primary-color); 45 | cursor: pointer; 46 | margin-bottom: 1.5rem; 47 | } 48 | 49 | .disabled { 50 | color: var(--secondary-color); 51 | cursor: not-allowed; 52 | margin-bottom: 1.5rem; 53 | } 54 | } 55 | } 56 | 57 | .linkArea:first-of-type { 58 | margin-left: 0; 59 | } 60 | } 61 | } 62 | 63 | .bottomArea { 64 | display: flex; 65 | justify-content: space-between; 66 | .codeArea { 67 | display: flex; 68 | flex-direction: column; 69 | .text { 70 | color: var(--secondary-color); 71 | } 72 | } 73 | .numArea { 74 | color: var(--secondary-color); 75 | display: flex; 76 | flex-direction: column; 77 | align-items: flex-end; 78 | font-weight: 400; 79 | font-size: 0.875rem; 80 | line-height: 1.25rem; 81 | 82 | span { 83 | margin-bottom: 0.75rem; 84 | } 85 | 86 | .publicLogo { 87 | display: flex; 88 | 89 | .logo { 90 | margin-right: 0.25rem; 91 | } 92 | } 93 | } 94 | } 95 | } 96 | 97 | @media screen and (min-width: 48.6875rem) and (max-width: 54.125rem) { 98 | .footer { 99 | .topArea { 100 | .footerTitle { 101 | margin-bottom: 1.25rem; 102 | } 103 | } 104 | } 105 | } 106 | 107 | @media screen and (max-width: 48.6875rem) { 108 | .footer { 109 | .topArea { 110 | display: flex; 111 | flex-direction: column; 112 | align-items: center; 113 | .footerTitle { 114 | margin-bottom: 2.5rem; 115 | } 116 | .linkListArea { 117 | display: flex; 118 | flex-direction: column; 119 | text-align: center; 120 | .linkArea { 121 | margin-left: 0; 122 | } 123 | } 124 | } 125 | 126 | .bottomArea { 127 | display: flex; 128 | flex-direction: column; 129 | align-items: center; 130 | 131 | .codeArea { 132 | display: flex; 133 | flex-direction: column; 134 | align-items: center; 135 | 136 | .text { 137 | text-align: center; 138 | margin: 1.25rem 0; 139 | } 140 | } 141 | 142 | .numArea { 143 | align-items: center; 144 | text-align: center; 145 | } 146 | } 147 | } 148 | } 149 | 150 | // @include media-ipad { 151 | // } 152 | -------------------------------------------------------------------------------- /pages/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useContext, useEffect, useRef, useState } from 'react'; 2 | import type { GetServerSideProps, GetStaticProps, NextPage } from 'next'; 3 | import styles from './index.module.scss'; 4 | import cName from 'classnames'; 5 | import { ThemeContext } from '@/stores/theme'; 6 | import { Pagination } from '@douyinfe/semi-ui'; 7 | import axios from 'axios'; 8 | import { LOCALDOMAIN } from '@/utils'; 9 | import { IArticleIntro } from './api/articleIntro'; 10 | import App from 'next/app'; 11 | import { IComponentProps } from './_app'; 12 | import Link from 'next/link'; 13 | import { useRouter } from 'next/router'; 14 | 15 | interface IProps { 16 | title: string; 17 | description: string; 18 | articles: { 19 | list: { 20 | label: string; 21 | info: string; 22 | link: string; 23 | }[]; 24 | total: number; 25 | }; 26 | } 27 | 28 | const Home: NextPage = ({ title, description, articles, isSupportWebp }) => { 29 | const [content, setContent] = useState(articles); 30 | const mainRef = useRef(null); 31 | const { theme } = useContext(ThemeContext); 32 | const router = useRouter(); 33 | 34 | useEffect(() => { 35 | mainRef.current?.classList.remove(styles.withAnimation); 36 | window.requestAnimationFrame(() => { 37 | mainRef.current?.classList.add(styles.withAnimation); 38 | }); 39 | }, [theme]); 40 | 41 | return ( 42 |
43 |
44 |
50 |

{title}

51 |

{description}

52 | 53 |
54 | {content?.list?.map((item, index) => ( 55 | 56 |
57 |

{item.label} →

58 |

{item.info}

59 |
60 | 61 | //
{ 65 | // router.push(item.link); 66 | // }} 67 | // > 68 | //

{item.label} →

69 | //

{item.info}

70 | //
71 | ))} 72 |
73 | { 77 | axios 78 | .post(`${LOCALDOMAIN}/api/articleIntro`, { 79 | pageNo, 80 | pageSize: 6, 81 | }) 82 | .then(({ data }) => { 83 | setContent({ 84 | list: data.list.map((item: IArticleIntro) => ({ 85 | label: item.label, 86 | info: item.info, 87 | link: `${LOCALDOMAIN}/article/${item.articleId}`, 88 | })), 89 | total: data.total, 90 | }); 91 | }); 92 | }} 93 | /> 94 |
95 |
96 |
97 |
98 | ); 99 | }; 100 | 101 | Home.getInitialProps = async (context): Promise => { 102 | const { data: homeData } = await axios.get(`${LOCALDOMAIN}/api/home`); 103 | const { data: articleData } = await axios.post(`${LOCALDOMAIN}/api/articleIntro`, { 104 | pageNo: 1, 105 | pageSize: 6, 106 | }); 107 | 108 | return { 109 | title: homeData.title, 110 | description: homeData.description, 111 | articles: { 112 | list: articleData.list.map((item: IArticleIntro) => ({ 113 | label: item.label, 114 | info: item.info, 115 | link: `${LOCALDOMAIN}/article/${item.articleId}`, 116 | })), 117 | total: articleData.total, 118 | }, 119 | }; 120 | }; 121 | 122 | // export const getServerSideProps: GetServerSideProps = async context => { 123 | // const { data: homeData } = await axios.get(`${LOCALDOMAIN}/api/home`); 124 | // const { data: articleData } = await axios.post(`${LOCALDOMAIN}/api/articleIntro`, { 125 | // pageNo: 1, 126 | // pageSize: 6, 127 | // }); 128 | 129 | // return { 130 | // props: { 131 | // title: homeData.title, 132 | // description: homeData.description, 133 | // articles: { 134 | // list: articleData.list.map((item: IArticleIntro) => ({ 135 | // label: item.label, 136 | // info: item.info, 137 | // link: `${LOCALDOMAIN}/article/${item.articleId}`, 138 | // })), 139 | // total: articleData.total, 140 | // }, 141 | // }, 142 | // }; 143 | // }; 144 | 145 | // export const getStaticProps: GetStaticProps = async context => { 146 | // const { data: homeData } = await axios.get(`${LOCALDOMAIN}/api/home`); 147 | // const { data: articleData } = await axios.post(`${LOCALDOMAIN}/api/articleIntro`, { 148 | // pageNo: 1, 149 | // pageSize: 6, 150 | // }); 151 | 152 | // return { 153 | // props: { 154 | // title: homeData.title, 155 | // description: homeData.description, 156 | // articles: { 157 | // list: articleData.list.map((item: IArticleIntro) => ({ 158 | // label: item.label, 159 | // info: item.info, 160 | // link: `${LOCALDOMAIN}/article/${item.articleId}`, 161 | // })), 162 | // total: articleData.total, 163 | // }, 164 | // }, 165 | // }; 166 | // }; 167 | 168 | export default Home; 169 | -------------------------------------------------------------------------------- /pages/index.module.scss: -------------------------------------------------------------------------------- 1 | @import "./media.scss"; 2 | 3 | @mixin initStatus { 4 | transform: translate3d(0, 2.5rem, 0); 5 | opacity: 0; 6 | } 7 | 8 | @mixin finalStatus { 9 | -webkit-transform: none; 10 | transform: none; 11 | opacity: 1; 12 | } 13 | 14 | .container { 15 | padding: 0 2rem; 16 | color: var(--primary-color); 17 | 18 | .main { 19 | min-height: 100vh; 20 | padding: 4rem 0; 21 | flex: 1; 22 | display: flex; 23 | flex-direction: column; 24 | justify-content: center; 25 | align-items: center; 26 | .header { 27 | background-image: var(--home-background-icon); 28 | background-size: 18.75rem 18.75rem; 29 | background-repeat: no-repeat; 30 | width: 18.75rem; 31 | height: 18.75rem; 32 | } 33 | 34 | .headerWebp { 35 | background-image: var(--home-background-icon-webp); 36 | } 37 | 38 | .top { 39 | display: flex; 40 | } 41 | 42 | .title a { 43 | color: var(--link-color); 44 | text-decoration: none; 45 | } 46 | 47 | .title a:hover, 48 | .title a:focus, 49 | .title a:active { 50 | text-decoration: underline; 51 | } 52 | 53 | .title { 54 | margin: 0; 55 | line-height: 1.15; 56 | font-size: 4rem; 57 | } 58 | 59 | .title, 60 | .description { 61 | text-align: center; 62 | } 63 | 64 | .description { 65 | margin: 4rem 0; 66 | line-height: 1.5; 67 | font-size: 1.5rem; 68 | } 69 | 70 | .grid { 71 | display: flex; 72 | align-items: flex-start; 73 | justify-content: flex-start; 74 | flex-wrap: wrap; 75 | max-width: 62.5rem; 76 | transition: 2s; 77 | min-height: 36.25rem; 78 | .card { 79 | margin: 1rem; 80 | padding: 1.5rem; 81 | text-align: left; 82 | color: inherit; 83 | text-decoration: none; 84 | border: 0.0625rem solid var(--footer-background-color); 85 | border-radius: 0.625rem; 86 | transition: color 0.15s ease, border-color 0.15s ease; 87 | max-width: 18.75rem; 88 | cursor: pointer; 89 | width: 18.75rem; 90 | height: 13.875rem; 91 | } 92 | 93 | .card:hover, 94 | .card:focus, 95 | .card:active { 96 | color: var(--link-color); 97 | border-color: var(--link-color); 98 | } 99 | 100 | .card h2 { 101 | margin: 0 0 1rem 0; 102 | font-size: 1.5rem; 103 | } 104 | 105 | .card p { 106 | margin: 0; 107 | font-size: 1.25rem; 108 | line-height: 1.5; 109 | } 110 | } 111 | 112 | .paginationArea { 113 | width: 62.5rem; 114 | display: flex; 115 | justify-content: flex-end; 116 | padding: 20px 0; 117 | 118 | :global { 119 | .semi-page-item { 120 | color: var(--primary-color); 121 | opacity: 0.7; 122 | } 123 | 124 | .semi-page-item:hover { 125 | background-color: var(--semi-page-hover-background-color); 126 | } 127 | 128 | .semi-page-item-active { 129 | color: var(--semi-page-active-color); 130 | background-color: var(--semi-page-active-background-color); 131 | } 132 | 133 | .semi-page-item-active:hover { 134 | color: var(--semi-page-active-color); 135 | background-color: var(--semi-page-active-background-color); 136 | } 137 | } 138 | } 139 | } 140 | 141 | .withAnimation { 142 | .title { 143 | animation: fadeInDown1 1s; 144 | } 145 | 146 | .description { 147 | animation: fadeInDown2 1s; 148 | } 149 | 150 | .card:nth-of-type(1) { 151 | animation: fadeInDown3 1s; 152 | } 153 | 154 | .card:nth-of-type(2) { 155 | animation: fadeInDown4 1s; 156 | } 157 | 158 | .card:nth-of-type(3) { 159 | animation: fadeInDown5 1s; 160 | } 161 | 162 | .card:nth-of-type(4) { 163 | animation: fadeInDown6 1s; 164 | } 165 | 166 | .card:nth-of-type(5) { 167 | animation: fadeInDown7 1s; 168 | } 169 | 170 | .card:nth-of-type(6) { 171 | animation: fadeInDown8 1s; 172 | } 173 | } 174 | 175 | @keyframes fadeInDown1 { 176 | 0% { 177 | @include initStatus; 178 | } 179 | 180 | 11% { 181 | @include initStatus; 182 | } 183 | 184 | 100% { 185 | @include finalStatus; 186 | } 187 | } 188 | 189 | @keyframes fadeInDown2 { 190 | 0% { 191 | @include initStatus; 192 | } 193 | 194 | 22% { 195 | @include initStatus; 196 | } 197 | 198 | 100% { 199 | @include finalStatus; 200 | } 201 | } 202 | 203 | @keyframes fadeInDown3 { 204 | 0% { 205 | @include initStatus; 206 | } 207 | 208 | 33% { 209 | @include initStatus; 210 | } 211 | 212 | 100% { 213 | @include finalStatus; 214 | } 215 | } 216 | 217 | @keyframes fadeInDown4 { 218 | 0% { 219 | @include initStatus; 220 | } 221 | 222 | 44% { 223 | @include initStatus; 224 | } 225 | 226 | 100% { 227 | @include finalStatus; 228 | } 229 | } 230 | 231 | @keyframes fadeInDown5 { 232 | 0% { 233 | @include initStatus; 234 | } 235 | 236 | 55% { 237 | @include initStatus; 238 | } 239 | 240 | 100% { 241 | @include finalStatus; 242 | } 243 | } 244 | 245 | @keyframes fadeInDown6 { 246 | 0% { 247 | @include initStatus; 248 | } 249 | 250 | 66% { 251 | @include initStatus; 252 | } 253 | 254 | 100% { 255 | @include finalStatus; 256 | } 257 | } 258 | 259 | @keyframes fadeInDown7 { 260 | 0% { 261 | @include initStatus; 262 | } 263 | 264 | 77% { 265 | @include initStatus; 266 | } 267 | 268 | 100% { 269 | @include finalStatus; 270 | } 271 | } 272 | 273 | @keyframes fadeInDown8 { 274 | 0% { 275 | @include initStatus; 276 | } 277 | 278 | 88% { 279 | @include initStatus; 280 | } 281 | 282 | 100% { 283 | @include finalStatus; 284 | } 285 | } 286 | } 287 | 288 | @include media-ipad { 289 | .container { 290 | .main { 291 | .grid { 292 | width: 95%; 293 | margin: auto; 294 | justify-content: center; 295 | } 296 | } 297 | } 298 | } 299 | 300 | @include media-mobile { 301 | .container { 302 | .main { 303 | .title { 304 | font-size: 1.75rem; 305 | line-height: 2.4375rem; 306 | } 307 | .description { 308 | font-size: 0.875rem; 309 | line-height: 1.5rem; 310 | margin: 2rem 0; 311 | } 312 | .grid { 313 | width: 95%; 314 | margin: auto; 315 | justify-content: center; 316 | .card { 317 | height: 10rem; 318 | h2 { 319 | font-size: 1.125rem; 320 | line-height: 1.5625rem; 321 | } 322 | p { 323 | font-size: 0.75rem; 324 | line-height: 1.625rem; 325 | } 326 | } 327 | } 328 | } 329 | } 330 | } 331 | --------------------------------------------------------------------------------