diff --git a/src/assets/css/bootstrap.css b/src/assets/css/bootstrap.css index e33ec3d..8e9dc65 100644 --- a/src/assets/css/bootstrap.css +++ b/src/assets/css/bootstrap.css @@ -287,10 +287,6 @@ textarea { font-size: inherit; line-height: inherit; } -a { - color: #1B242F; - text-decoration: none; -} a:focus { outline: thin dotted; diff --git a/src/components/Breadcrumb.astro b/src/components/Breadcrumb.astro index 9b74f3a..64b7fb2 100644 --- a/src/components/Breadcrumb.astro +++ b/src/components/Breadcrumb.astro @@ -15,12 +15,9 @@ const {data} = Astro.props; \ No newline at end of file diff --git a/src/pages/news.astro b/src/pages/news.astro index 50b3ef4..6cb7de3 100644 --- a/src/pages/news.astro +++ b/src/pages/news.astro @@ -1,4 +1,10 @@ --- +export interface Props { + page: number; + columnDesc: string; + breadcrumb: []; + filter: [] +} import Layout from "../layouts/Layout.astro"; import { getConfig } from "../../utils/config"; import "../assets/css1/style.css"; @@ -13,15 +19,22 @@ const config = getConfig(Astro); const limit = 10; // 页码 -const { page = 1, columnDesc = `霍尔果斯飞驰广告有限公司致力于分享从基础到进阶的SEO优化策略、广告投放方法、内容运营技巧和网站转化率提升方案。` ,breadcrumb = [{ title: "资讯", link: "/news" }] } = Astro.props; -const { code, data, total = 0, hot } = await newsIndex(config.id, limit, page); - -if (!data || code !== 0) { +const { + page = Astro.locals?.column_page || 1, // 页码 + columnDesc = Astro.locals?.column_data?.desc || `霍尔果斯飞驰广告有限公司致力于分享从基础到进阶的SEO优化策略、广告投放方法、内容运营技巧和网站转化率提升方案。` , + breadcrumb = Astro.locals?.column_data?.item || [{ title: "资讯", link: "/news" }], // 面包屑导航 + filter = Astro.locals?.column_data?.filter || [], // 面包屑导航 +} = Astro.props; +const { code, data, total = 0, hot } = await newsIndex(config.id, limit, page, filter); +if (data.length == 0 || code !== 0) { return Astro.redirect("/404"); } + --- - +
@@ -40,7 +53,7 @@ if (!data || code !== 0) {
{ - data?.map((e) => { + data?.map((e, index) => { return (
@@ -51,7 +64,7 @@ if (!data || code !== 0) { title={`${e.title}`} > 2 ? 'lazy' : 'eager'} style={`aspect-ratio: 4 / 3;object-fit: cover;`} src={e.cover} alt={e.title} @@ -85,7 +98,8 @@ if (!data || code !== 0) { {e.description}

- {e.column_tag} + {e.column_tag ? {e.column_tag} : ''} + {e.second_column_tag ? {e.second_column_tag} : ''} {/* {e.column_tag} */}
@@ -98,7 +112,7 @@ if (!data || code !== 0) {
@@ -116,6 +130,7 @@ if (!data || code !== 0) { title={item.title} > {item.title} - 2025-02-27 + {item.created_at} ); diff --git a/src/pages/news/[...slug].astro b/src/pages/news/[...slug].astro index 43a3c42..6b4fbd3 100644 --- a/src/pages/news/[...slug].astro +++ b/src/pages/news/[...slug].astro @@ -1,26 +1,61 @@ --- import Layout from "../../layouts/Layout.astro"; import { getConfig } from "../../../utils/config"; -import { newsDetail } from "../../../utils/rpc"; +import { newsDetail, columns as getColumns } from "../../../utils/rpc"; import Breadcrumb from "../../components/Breadcrumb.astro"; +import { formatDate } from "../../../utils/date"; const { slug } = Astro.params; const config = getConfig(Astro); const requestUrl = Astro.request.url; -const breadcrumb = [{title: '资讯', link: '/news'},{title: '教程', link: '/news/tech'}, {title: '正文', link: ''}] -if (!slug) { - return Astro.redirect("/404"); +let requestUri = Astro.originPathname +let page = 1; +var breadcrumb = [{title: '资讯', link: '/news'},{title: '教程经验', link: '/news/tech'}, {title: '正文', link: ''}] + +//---------------------------------栏目rewrite------------------------------------- +// 定义正则表达式来匹配分页路径:/news/tech/page/{number} +const regex = /^(\/news\/.+)\/page\/(\d+)$/; +const match = requestUri.match(regex); +// 如果发现分页了, uri 就移除掉分页参数, 并且做rewrite +if (match && match[1]) { + requestUri = match[1] + page = Number(match[2]) } -const { code, data } = await newsDetail(slug, config); -if (!data || code !== 0) { - return Astro.redirect("/404"); +// 如果请求的是栏目跳转到news, 如果请求的是页面 则渲染。后期可以考虑用nginx转发 +const col = await getColumns(config.id) +const columns = col.data + +const currentRequestPath = requestUri +const val = columns?.find(data => data.path === currentRequestPath); +if (val) { + Astro.locals.column_data = val // 当前栏目数据 + Astro.locals.column_base_uri = requestUri // 当前去除掉页码信息的baseUri + Astro.locals.column_page = page// 页码数据 + return Astro.rewrite(`/news`); } +//---------------------------------------------------------------------- + +if (!slug) { + return Astro.rewrite("/404"); +} + +var { code, data } = await newsDetail(slug, config); +if (!data || code !== 0) { + return Astro.rewrite("/404"); +} + +const bytedanceData = formatDate(data.created_at) --- + + + `} >
@@ -32,7 +67,6 @@ if (!data || code !== 0) {
-
@@ -43,10 +77,11 @@ if (!data || code !== 0) {

{data.title}

- {data.created_at} - {data.column_tag} +
+ {data.created_at} + {data.column_tag} + {data.second_column} +
@@ -242,6 +277,10 @@ if (!data || code !== 0) { border-bottom: none !important; padding: unset !important; font-weight: unset; + a { + color: #999 !important; + font-size: 14px; + } } header > h1 { @@ -249,6 +288,17 @@ if (!data || code !== 0) { }