日韩成人免费在线_国产成人一二_精品国产免费人成电影在线观..._日本一区二区三区久久久久久久久不

當前位置:首頁 > 科技  > 軟件

lowcode-cms開源社區源碼設計分享

來源: 責編: 時間:2024-01-25 10:41:57 240觀看
導讀開源背景lowcode可視化社區 是我之前在設計研發 Dooring低代碼 平臺時開發的一個面向低代碼內容分享的知識社區, 內容端采用 SSR 技術來渲染頁面, 對 SEO 更加友好, 同時后端服務采用 Nodejs 來實現, 內容端和服務端

t2928資訊網——每日最新資訊28at.com

開源背景

lowcode可視化社區 是我之前在設計研發 Dooring低代碼 平臺時開發的一個面向低代碼內容分享的知識社區, 內容端采用 SSR 技術來渲染頁面, 對 SEO 更加友好, 同時后端服務采用 Nodejs 來實現, 內容端和服務端同端, 也就是傳說中的內容服務“同構”. 管理端采用前端最最流行的 React hooks 來實現, 無論是技術人員還是非技術人員, 通過簡單的操作就可以輕松部署一套專屬自己的 CMS 系統。t2928資訊網——每日最新資訊28at.com

本著滿滿的開源精神, 我對這套 CMS 系統進行了開源, 讓更多技術小白或者非技術人員, 可以輕松部署自己的網站。t2928資訊網——每日最新資訊28at.com

接下來我會從技術的角度, 分享一下我開源的 lowcode-cms 系統的技術實現, 以及如何本地運行 + 部署這套開箱即用的 CMS 系統。t2928資訊網——每日最新資訊28at.com

系統設計架構

t2928資訊網——每日最新資訊28at.com

接下來我會具體和大家介紹一下管理端, 內容端, 服務端的技術架構。內容端架構設計t2928資訊網——每日最新資訊28at.com

內容端主要用來展現個人或者企業的內容信息, 相當于一個門戶站, 這里為了更好的 SEO, 我采用了模版引擎來渲染 html, 也就是koa-views +  pug 模式, 具體界面如下:t2928資訊網——每日最新資訊28at.com

t2928資訊網——每日最新資訊28at.com

當然這只是首頁模塊, 還有諸如行業產品, 最佳實踐, 視頻, 手記等, 這里就不一一介紹了, 大家如果會編程的話, 也可以自定義自己的模塊頁面. 我們接下來看看具體的技術實現。t2928資訊網——每日最新資訊28at.com

t2928資訊網——每日最新資訊28at.com

大家可以在github中server的views目錄下看到每個渲染層的具體實現, 這里和大家分享一下 lowcode-cms 搭建的ssr模式。t2928資訊網——每日最新資訊28at.com

1、配置pug支持

import koa from "koa";import views from "koa-views";// ... (此處省略服務端自治的部分代碼)// 掛載路由glob.sync(`${config.routerPath}/*.js`).forEach((item) => {  require(item).default(router, config.API_VERSION_PATH);});//使用模版引擎app.use(views(resolve(__dirname, "./views"), { extension: "pug" }));app.use(router.routes()).use(router.allowedMethods());

2、ssr路由數據直出

這塊主要是基于用戶發起的請求, 在服務端格式化好數據供 pug 消費:t2928資訊網——每日最新資訊28at.com

/** * 文章路由 * @param {*} router * @param {*} apiPath */const pageRenderRouter = (router) => {  // api路徑  const api = {    // 渲染首頁    index: "/",    // 最佳實踐列表    bestPractice: "/best-practice",    product: "/product",    video: "/video",    note: "/note",    login: "/login",    // 其他渲染路由...  };  // 內容端導航配置  const nav = [    {      id: "0",      title: "最佳實踐",      link: "/best-practice"    },    {      id: "1",      title: "行業產品",      link: "/product"    },    {      id: "3",      title: "視頻",      link: "/video"    },    {      id: "4",      title: "手記",      link: "/note"    },    {      id: "5",      title: "關于",      link: "/about"    },  ]  const copyright = "版權所有 @lowcode可視化社區"  // 登錄  router.get(api.login, async (ctx) => {    await ctx.render("login", {      url: api.login,      title: "登錄",      description: "新用戶?",      href: "去注冊",      firstInput: "郵箱",      twoInput: "密碼",      btnText: "登錄",      logoText: "Dooring低代碼社區",    });  });  // 渲染首頁  router.get(api.index, async (ctx) => {    const filePath = `${config.publicPath}/db/homeConfig.json`;    const articlesPath = `${config.publicPath}/db/article_index.json`;    const productsPath = `${config.publicPath}/db/product_index.json`;    const videosPath = `${config.publicPath}/db/video_index.json`;    const homeConfig = RF(filePath);    const articles = RF(articlesPath);    const products = RF(productsPath);    const videos = RF(videosPath);    await ctx.render("index", {      nav,      articles: articles.filter(v => v.review === 1).slice(0, 6),      products: products.filter(v => v.review === 1).slice(0, 6),      videos: videos.filter(v => v.review === 1).slice(0, 6),      copyright,      ...homeConfig    });    // 統計訪問量    const viewPath = `${config.publicPath}/db/views.json`;    const views = RF(viewPath);    WF(viewPath, {...views, home: views.home + 1});  });  // 渲染文章詳情頁  router.get(api.articleDetail, async (ctx) => {    const id = ctx.query.fid;    const articlePath = `${config.publicPath}/db/articles/${id}.json`;    const commentPath = `${config.publicPath}/db/comments/${id}.json`;    const article = RF(articlePath) || {};    const comments = RF(commentPath) || {};    comments.views = comments.views + 1;    await ctx.render("article_detail", {      nav,      viewTitle: article.title,      topImg: article.img,      authorInfo: { name: article.author, date: formatTime(article.ct, "-") },      cate: article.cate,      val:  article.type ? marked(article.val) : article.val,      commentInfoList: comments.comments || [],      flover: comments.flover,      views: comments.views || 0,      copyright,    });    WF(commentPath, comments);  });  // 其他頁面渲染服務邏輯...  });};export default pageRenderRouter;

3、模版消費

這里給大家參考一個我寫的 pug 頁面的例子:t2928資訊網——每日最新資訊28at.com

t2928資訊網——每日最新資訊28at.com

大家感興趣的可以參考一下具體的實現:t2928資訊網——每日最新資訊28at.com

https://github.com/MrXujiang/lowcode-cmst2928資訊網——每日最新資訊28at.com

服務端架構設計

t2928資訊網——每日最新資訊28at.com

服務端本質上主要實現兩塊能力:t2928資訊網——每日最新資訊28at.com

  • 內容端頁面渲染(SSR)
  • 后臺API和三方接口服務對接

服務端我參考了通用后端服務的 MVC 模式, 基于 koa2 搭建了一個簡易的服務端 MVC 模型, 如下是一個服務端的代碼目錄:t2928資訊網——每日最新資訊28at.com

t2928資訊網——每日最新資訊28at.com

主要實現的核心模塊有:t2928資訊網——每日最新資訊28at.com

  • 靜態資源服務器
  • 微信分享, CDN上傳等第三方服務模塊
  • api路由
  • 中間件模塊
  • 資源上傳模塊
  • 用戶權限模塊
  • ssr服務模塊

如果搭建感興趣可以參考 github 中具體的實現代碼:https://github.com/MrXujiang/lowcode-cmst2928資訊網——每日最新資訊28at.com

管理端系統架構設計

t2928資訊網——每日最新資訊28at.com

t2928資訊網——每日最新資訊28at.com

管理端采用的是 umi + react + antd4.0 實現的, 當然封裝了很多成熟的插件模塊, 比如說 富文本編輯器, md編輯器, 文件上傳模塊等, 大家可以在學習源碼的過程中受益非淺。t2928資訊網——每日最新資訊28at.com

t2928資訊網——每日最新資訊28at.com

上圖就是編輯模塊, 我封裝了實時預覽 md 和富文本的模塊, 大家可以拿來即用。t2928資訊網——每日最新資訊28at.com

本地運行

1、目錄介紹

  • server 基于nodejs的服務端, 啟動后可直接訪問3000 端口, 也就是內容SSR端。
  • admin CMS的管理后臺, 集成了用戶管理, 內容審核, 內容發布, 數據統計等模塊。

開箱即用~~t2928資訊網——每日最新資訊28at.com

2、本地啟動

server端:t2928資訊網——每日最新資訊28at.com

# 進入server目錄cd server# 安裝依賴yarn# 服務端啟動yarn start

注: 如果是window系統, 可以執行 yarn start:win。t2928資訊網——每日最新資訊28at.com

管理端:t2928資訊網——每日最新資訊28at.com

# 進入admin目錄cd admin# 安裝依賴yarn# 啟動yarn start

初始化賬號: super_123, 密碼: zxzk_123。t2928資訊網——每日最新資訊28at.com

內容端:t2928資訊網——每日最新資訊28at.com

訪問3000端口即可。t2928資訊網——每日最新資訊28at.com

部署發布

推薦使用 pm2 來管理 Node 服務進程, 只需要把 server 端上傳到服務器, 安裝對應依賴, 用 pm2 啟動即可:t2928資訊網——每日最新資訊28at.com

pm2 start server/dist

有關 pm2 相關問題可以在我往期的文章中學習參考。t2928資訊網——每日最新資訊28at.com

本文鏈接:http://www.www897cc.com/showinfo-26-67850-0.htmllowcode-cms開源社區源碼設計分享

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 獲取雙異步返回值時,如何保證主線程不阻塞?

下一篇: 微軟 Visual Studio 2022 獲推 17.9 Preview 3 更新:增強代碼搜索體驗

標簽:
  • 熱門焦點
Top 主站蜘蛛池模板: 宁南县| 麻栗坡县| 辰溪县| 绵阳市| 临汾市| 武夷山市| 深水埗区| 汾阳市| 大埔区| 八宿县| 河东区| 青冈县| 塘沽区| 博罗县| 北辰区| 梧州市| 蒙阴县| 宿州市| 宁夏| 灵宝市| 灵丘县| 苏尼特左旗| 多伦县| 永定县| 乌拉特中旗| 霞浦县| 五常市| 南溪县| 浠水县| 台中县| 光泽县| 蒲城县| 泗洪县| 涞水县| 洪洞县| 清河县| 彩票| 开封县| 晋州市| 成安县| 松阳县|