更新网站功能
This commit is contained in:
@@ -3,6 +3,9 @@ package controllers
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -17,6 +20,31 @@ type IndexPortalController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// reNewsRow 从模板标签 {yz:newscenter row="N" ...} 中提取 row 值
|
||||
var reNewsRow = regexp.MustCompile(`\{yz:newscenter[^}]*\s+row\s*=\s*"(\d+)"`)
|
||||
|
||||
// templateNewsRow 读取当前租户首页模板中 newscenter 标签的 row 参数,
|
||||
// 作为 API 默认条数,使接口与前端模板保持一致。
|
||||
func templateNewsRow(tid uint64) int {
|
||||
code := strings.TrimSpace(cmsTenantTemplateCode(tid))
|
||||
if code == "" || code == "default" {
|
||||
code = "default"
|
||||
}
|
||||
if !cmsTemplateDirExists(code) {
|
||||
code = "default"
|
||||
}
|
||||
data, err := os.ReadFile(filepath.Join(cmsThemesRoot(), code, "index.html"))
|
||||
if err != nil {
|
||||
return 10
|
||||
}
|
||||
if m := reNewsRow.FindSubmatch(data); len(m) == 2 {
|
||||
if n, e := strconv.Atoi(string(m[1])); e == nil && n > 0 && n <= 50 {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return 10
|
||||
}
|
||||
|
||||
// getTidByHost 根据访问域名识别租户 ID,默认返回 1
|
||||
func (c *IndexPortalController) getTidByHost() uint64 {
|
||||
host := c.Ctx.Request.Host
|
||||
@@ -267,13 +295,15 @@ func (c *IndexPortalController) queryCmsArticles(categoryName string, categoryID
|
||||
tid := c.getTidByHost()
|
||||
_ = models.EnsureCmsArticleTables()
|
||||
|
||||
defaultLimit := templateNewsRow(tid)
|
||||
|
||||
page, _ := c.GetInt("page", 1)
|
||||
limit, _ := c.GetInt("limit", 10)
|
||||
limit, _ := c.GetInt("limit", defaultLimit)
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if limit < 1 {
|
||||
limit = 10
|
||||
limit = defaultLimit
|
||||
}
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.CmsArticle)).
|
||||
|
||||
@@ -136,7 +136,7 @@ func (c *TenantSiteController) rewriteStorageURLs(html string) string {
|
||||
if err != nil || strings.TrimSpace(cfg.QiniuDomain) == "" {
|
||||
return html
|
||||
}
|
||||
return rewriteLegacyQiniuURLs(html, storagePublicBaseURL(cfg.QiniuDomain))
|
||||
return rewriteLegacyQiniuURLs(html, storagePublicBaseURL(cfg.QiniuDomain), cfg.QiniuDomain)
|
||||
}
|
||||
|
||||
func storagePublicBaseURL(domain string) string {
|
||||
@@ -147,13 +147,18 @@ func storagePublicBaseURL(domain string) string {
|
||||
return "https://" + base
|
||||
}
|
||||
|
||||
func rewriteLegacyQiniuURLs(html, targetBase string) string {
|
||||
func rewriteLegacyQiniuURLs(html, targetBase, qiniuDomain string) string {
|
||||
if targetBase == "" {
|
||||
return html
|
||||
}
|
||||
for _, domain := range legacyQiniuDomains {
|
||||
domains := append(legacyQiniuDomains, qiniuDomain)
|
||||
for _, domain := range domains {
|
||||
d := strings.TrimSpace(domain)
|
||||
if d == "" {
|
||||
continue
|
||||
}
|
||||
for _, scheme := range []string{"http://", "https://"} {
|
||||
html = strings.ReplaceAll(html, scheme+domain+"/", targetBase+"/")
|
||||
html = strings.ReplaceAll(html, scheme+d+"/", targetBase+"/")
|
||||
}
|
||||
}
|
||||
return html
|
||||
|
||||
@@ -126,6 +126,23 @@ func CmsCategoryNameMap(tid uint64, ids []uint64) map[uint64]string {
|
||||
return out
|
||||
}
|
||||
|
||||
func CmsCategoryImageMap(tid uint64, ids []uint64) map[uint64]string {
|
||||
out := make(map[uint64]string)
|
||||
if len(ids) == 0 {
|
||||
return out
|
||||
}
|
||||
var rows []CmsArticleCategory
|
||||
qs := Orm.QueryTable(new(CmsArticleCategory)).
|
||||
Filter("id__in", ids).
|
||||
Filter("delete_time__isnull", true)
|
||||
cond := orm.NewCondition().Or("tid", 0).Or("tid", tid)
|
||||
_, _ = qs.SetCond(cond).All(&rows, "ID", "Image")
|
||||
for _, r := range rows {
|
||||
out[r.ID] = r.Image
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func CmsFormatTime(t *time.Time) string {
|
||||
if t == nil {
|
||||
return ""
|
||||
|
||||
@@ -426,11 +426,12 @@ func arclistProvider(tid uint64, params map[string]string, ctx *RenderCtx) ([]ma
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
return articleRows(rows, titleLen), nil
|
||||
cateImgMap := models.CmsCategoryImageMap(tid, collectCateIDs(rows))
|
||||
return articleRows(rows, titleLen, cateImgMap), nil
|
||||
}
|
||||
|
||||
// articleRows 文章行转标签字段
|
||||
func articleRows(rows []models.CmsArticle, titleLen int) []map[string]string {
|
||||
func articleRows(rows []models.CmsArticle, titleLen int, cateImgMap map[uint64]string) []map[string]string {
|
||||
out := make([]map[string]string, 0, len(rows))
|
||||
for _, a := range rows {
|
||||
pub := ""
|
||||
@@ -443,12 +444,16 @@ func articleRows(rows []models.CmsArticle, titleLen int) []map[string]string {
|
||||
if titleLen > 0 {
|
||||
title = truncateTitle(title, titleLen)
|
||||
}
|
||||
img := a.Image
|
||||
if img == "" {
|
||||
img = cateImgMap[a.CateID]
|
||||
}
|
||||
out = append(out, map[string]string{
|
||||
"id": strconv.FormatUint(a.ID, 10),
|
||||
"title": title,
|
||||
"titlefull": a.Title,
|
||||
"desc": a.Desc,
|
||||
"image": a.Image,
|
||||
"image": img,
|
||||
"arcurl": "/news/" + strconv.FormatUint(a.ID, 10),
|
||||
"pubdate": pub,
|
||||
"views": strconv.Itoa(a.Views),
|
||||
@@ -458,6 +463,19 @@ func articleRows(rows []models.CmsArticle, titleLen int) []map[string]string {
|
||||
return out
|
||||
}
|
||||
|
||||
// collectCateIDs 从文章列表中收集不重复的分类 ID
|
||||
func collectCateIDs(rows []models.CmsArticle) []uint64 {
|
||||
seen := make(map[uint64]bool)
|
||||
var ids []uint64
|
||||
for _, a := range rows {
|
||||
if a.CateID > 0 && !seen[a.CateID] {
|
||||
seen[a.CateID] = true
|
||||
ids = append(ids, a.CateID)
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// arcviewProvider 文章详情(详情页模板内),取当前路由文章
|
||||
func arcviewProvider(tid uint64, params map[string]string, ctx *RenderCtx) ([]map[string]string, error) {
|
||||
if ctx.ArticleID == 0 {
|
||||
@@ -478,12 +496,17 @@ func arcviewProvider(tid uint64, params map[string]string, ctx *RenderCtx) ([]ma
|
||||
} else {
|
||||
pub = a.CreateTime.Format(datetimeLayout)
|
||||
}
|
||||
img := a.Image
|
||||
if img == "" && a.CateID > 0 {
|
||||
cateImgMap := models.CmsCategoryImageMap(tid, []uint64{a.CateID})
|
||||
img = cateImgMap[a.CateID]
|
||||
}
|
||||
return []map[string]string{{
|
||||
"id": strconv.FormatUint(a.ID, 10),
|
||||
"title": a.Title,
|
||||
"content": a.Content,
|
||||
"desc": a.Desc,
|
||||
"image": a.Image,
|
||||
"image": img,
|
||||
"author": a.Author,
|
||||
"pubdate": pub,
|
||||
"views": strconv.Itoa(a.Views),
|
||||
@@ -547,12 +570,34 @@ func newscenterHandler(tid uint64, params map[string]string, ctx *RenderCtx, bod
|
||||
All(&children)
|
||||
}
|
||||
|
||||
// collectDescendantIDs 递归收集分类及其所有子孙分类 ID
|
||||
collectDescendantIDs := func(rootID uint64) []uint64 {
|
||||
ids := []uint64{rootID}
|
||||
queue := []uint64{rootID}
|
||||
for len(queue) > 0 {
|
||||
pid := queue[0]
|
||||
queue = queue[1:]
|
||||
var subs []models.CmsArticleCategory
|
||||
_, _ = models.Orm.QueryTable(new(models.CmsArticleCategory)).
|
||||
Filter("cid", pid).
|
||||
Filter("tid__in", []uint64{0, tid}).
|
||||
Filter("status", 1).
|
||||
Filter("delete_time__isnull", true).
|
||||
All(&subs)
|
||||
for _, s := range subs {
|
||||
ids = append(ids, s.ID)
|
||||
queue = append(queue, s.ID)
|
||||
}
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
renderCards := func(cateID uint64) string {
|
||||
qs := publishedCond(models.Orm.QueryTable(new(models.CmsArticle)).
|
||||
Filter("tid", tid).
|
||||
Filter("delete_time__isnull", true))
|
||||
if cateID > 0 {
|
||||
qs = qs.Filter("cate_id", cateID)
|
||||
qs = qs.Filter("cate_id__in", collectDescendantIDs(cateID))
|
||||
} else if parent != nil {
|
||||
ids := []uint64{parent.ID}
|
||||
for _, c := range children {
|
||||
@@ -562,8 +607,9 @@ func newscenterHandler(tid uint64, params map[string]string, ctx *RenderCtx, bod
|
||||
}
|
||||
var arts []models.CmsArticle
|
||||
_, _ = qs.OrderBy("-top", "-id").Limit(row).All(&arts)
|
||||
cateImgMap := models.CmsCategoryImageMap(tid, collectCateIDs(arts))
|
||||
var sb strings.Builder
|
||||
for _, a := range articleRows(arts, titleLen) {
|
||||
for _, a := range articleRows(arts, titleLen, cateImgMap) {
|
||||
sb.WriteString(applyFields(body, a))
|
||||
}
|
||||
return sb.String()
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
{yz:arclist row="4" titlelen="24"}
|
||||
<li class="yz-news-card">
|
||||
<a href="[field:arcurl/]">
|
||||
<img class="yz-news-thumb" src="[field:image/]" alt="[field:titlefull/]" onerror="this.style.display='none'">
|
||||
<img class="yz-news-thumb" src="[field:image/]" alt="[field:titlefull/]">
|
||||
<h3 title="[field:titlefull/]">[field:title/]</h3>
|
||||
<p class="yz-news-desc">[field:desc/]</p>
|
||||
<span class="yz-news-date">[field:pubdate/]</span>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<div class="col-lg-12">
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<a class="navbar-brand" href="/">
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" />
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" style="width: 200px;" />
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNine"
|
||||
aria-controls="navbarNine" aria-expanded="false" aria-label="切换导航">
|
||||
@@ -121,7 +121,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-12">
|
||||
<div class="footer-widget f-about">
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" /></a></div>
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" style="width: 250px;" /></a></div>
|
||||
<p>{yz:description}</p>
|
||||
<p class="copyright-text">
|
||||
<span>备案号:{yz:icp}<br>{yz:copyright} <a href="www.yunzer.cn" rel="nofollow"> 云泽网 </a></span>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<div class="col-lg-12">
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<a class="navbar-brand" href="/">
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" />
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" style="width: 200px;" />
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNine"
|
||||
aria-controls="navbarNine" aria-expanded="false" aria-label="切换导航">
|
||||
@@ -185,7 +185,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-12">
|
||||
<div class="footer-widget f-about">
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" /></a></div>
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" style="width: 250px;" /></a></div>
|
||||
<p>{yz:description}</p>
|
||||
<p class="copyright-text">
|
||||
<span>备案号:{yz:icp}<br>{yz:copyright} <a href="www.yunzer.cn" rel="nofollow"> 云泽网 </a></span>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<div class="col-lg-12">
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<a class="navbar-brand" href="/">
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" />
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" style="width: 200px;" />
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNine"
|
||||
aria-controls="navbarNine" aria-expanded="false" aria-label="切换导航">
|
||||
@@ -168,7 +168,7 @@
|
||||
<div class="col-lg-3 col-md-6 col-12">
|
||||
<div class="single-news news-center-item">
|
||||
<div class="image">
|
||||
<a href="[field:arcurl/]"><img class="thumb" src="[field:image/]" alt="[field:titlefull/]" onerror="this.style.display='none'" /></a>
|
||||
<a href="[field:arcurl/]"><img class="thumb" src="[field:image/]" alt="[field:titlefull/]" /></a>
|
||||
<div class="meta-details">
|
||||
<span>[field:pubdate/]</span>
|
||||
</div>
|
||||
@@ -500,11 +500,7 @@
|
||||
<div class="col-lg-4 col-md-6 col-12">
|
||||
<!-- 单个小组件 -->
|
||||
<div class="footer-widget f-about">
|
||||
<div class="logo">
|
||||
<a href="/">
|
||||
<img src="{yz:logo}" alt="云泽网" class="img-fluid" />
|
||||
</a>
|
||||
</div>
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" style="width: 250px;" /></a></div>
|
||||
<p>
|
||||
{yz:description}
|
||||
</p>
|
||||
@@ -606,15 +602,6 @@
|
||||
overlayLeft.classList.add("open");
|
||||
});
|
||||
|
||||
//========= 初始化 glightbox 视频播放
|
||||
GLightbox({
|
||||
'href': 'https://www.youtube.com/watch?v=r44RKWyfcFw&fbclid=IwAR21beSJORalzmzokxDRcGfkZA1AtRTE__l5N4r09HcGS5Y6vOluyouM9EM',
|
||||
'type': 'video',
|
||||
'source': 'youtube', // vimeo, youtube 或本地视频
|
||||
'width': 900,
|
||||
'autoplayVideos': true,
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<div class="col-lg-12">
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<a class="navbar-brand" href="/">
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" />
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" style="width: 200px;" />
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNine"
|
||||
aria-controls="navbarNine" aria-expanded="false" aria-label="切换导航">
|
||||
@@ -122,11 +122,11 @@
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
{yz:arclist row="10" titlelen="40"}
|
||||
{yz:arclist row="8" titlelen="40"}
|
||||
<div class="col-lg-3 col-md-6 col-12">
|
||||
<div class="single-news news-center-item">
|
||||
<div class="image">
|
||||
<a href="[field:arcurl/]"><img class="thumb" src="[field:image/]" alt="[field:titlefull/]" onerror="this.style.display='none'" /></a>
|
||||
<a href="[field:arcurl/]"><img class="thumb" src="[field:image/]" alt="[field:titlefull/]" /></a>
|
||||
<div class="meta-details">
|
||||
<span>[field:pubdate/]</span>
|
||||
</div>
|
||||
@@ -159,11 +159,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-12">
|
||||
<div class="footer-widget f-about">
|
||||
<div class="logo">
|
||||
<a href="/">
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" />
|
||||
</a>
|
||||
</div>
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" style="width: 250px;" /></a></div>
|
||||
<p>{yz:description}</p>
|
||||
<p class="copyright-text">
|
||||
<span>备案号:{yz:icp}<br>{yz:copyright} <a href="www.yunzer.cn" rel="nofollow"> 云泽网 </a></span>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<div class="col-lg-12">
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<a class="navbar-brand" href="/">
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" />
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" style="width: 200px;" />
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNine"
|
||||
aria-controls="navbarNine" aria-expanded="false" aria-label="切换导航">
|
||||
@@ -114,8 +114,8 @@
|
||||
<div class="col-lg-10 col-xl-9">
|
||||
{yz:arcview}
|
||||
<article class="article-detail-card">
|
||||
<div class="article-detail-thumb" style="display:none;">
|
||||
<img src="[field:image/]" alt="[field:title/]" class="article-cover" onerror="this.closest('.article-detail-thumb').style.display='none'" onload="this.closest('.article-detail-thumb').style.display='block'" />
|
||||
<div class="article-detail-thumb">
|
||||
<img src="[field:image/]" alt="[field:title/]" class="article-cover" onerror="this.closest('.article-detail-thumb').style.display='none'" />
|
||||
</div>
|
||||
|
||||
<h1 class="article-detail-title">[field:title/]</h1>
|
||||
@@ -151,11 +151,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-12">
|
||||
<div class="footer-widget f-about">
|
||||
<div class="logo">
|
||||
<a href="/">
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" />
|
||||
</a>
|
||||
</div>
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" style="width: 250px;" /></a></div>
|
||||
<p>{yz:description}</p>
|
||||
<p class="copyright-text">
|
||||
<span>备案号:{yz:icp}<br>{yz:copyright} <a href="www.yunzer.cn" rel="nofollow"> 云泽网 </a></span>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<div class="col-lg-12">
|
||||
<nav class="navbar navbar-expand-lg">
|
||||
<a class="navbar-brand" href="/">
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" />
|
||||
<img src="{yz:logo}" alt="{yz:sitename}" style="width: 200px;" />
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNine"
|
||||
aria-controls="navbarNine" aria-expanded="false" aria-label="切换导航">
|
||||
@@ -114,7 +114,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-4 col-md-6 col-12">
|
||||
<div class="footer-widget f-about">
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" /></a></div>
|
||||
<div class="logo"><a href="/"><img src="{yz:logo}" alt="{yz:sitename}" class="img-fluid" style="width: 250px;" /></a></div>
|
||||
<p>{yz:description}</p>
|
||||
<p class="copyright-text">
|
||||
<span>备案号:{yz:icp}<br>{yz:copyright} <a href="www.yunzer.cn" rel="nofollow"> 云泽网 </a></span>
|
||||
|
||||
Reference in New Issue
Block a user