浏览代码

added ability to view custom json templates

lllllllillllllillll 1 年之前
父节点
当前提交
319aab60f5
共有 6 个文件被更改,包括 25 次插入21 次删除
  1. 2 2
      CHANGELOG.md
  2. 1 1
      Dockerfile
  3. 22 18
      controllers/apps.js
  4. 0 0
      templates/json/default.json
  5. 0 0
      templates/json/foss.json
  6. 0 0
      templates/json/templates-bak.json

+ 2 - 2
CHANGELOG.md

@@ -1,6 +1,6 @@
 ## v0.60 (dev)
-* Converted template literals into html.
-* Converted modals into html/htmx.
+* Converted JS template literals into HTML.
+* Converted modals into HTML/HTMX.
 * Moved functions into dashboard controller.
 * Added modal placeholder with loading spinner.
 * Independently updating container cards.

+ 1 - 1
Dockerfile

@@ -1,4 +1,4 @@
-FROM node:21-alpine
+FROM node:22-alpine
 ENV NODE_ENV=production
 WORKDIR /app
 COPY . /app

+ 22 - 18
controllers/apps.js

@@ -6,28 +6,22 @@ const upload = multer({storage: multer.diskStorage({
   filename: function (req, file, cb) { cb(null, file.originalname) },
 })});
 
-
-// load the default template then sort the templates by name
-let templatesJSON = readFileSync('./templates/templates.json');
-
-let templates = JSON.parse(templatesJSON).templates;
-
-templates = templates.sort((a, b) => {
-    if (a.name < b.name) { return -1; }
-});
-
 let alert = '';
 
-
-
 export const Apps = (req, res) => {
   
   let page = Number(req.params.page) || 1;
-  let custom_template = req.params.template;
+  let template_param = req.params.template || 'default';
+
+  let template_file = readFileSync(`./templates/json/${template_param}.json`);
+
+  let templates = JSON.parse(template_file).templates;
+
+  templates = templates.sort((a, b) => {
+      if (a.name < b.name) { return -1; }
+  });
+
 
-  if (custom_template) {
-    console.log(custom_template);
-  }
 
   let list_start = (page-1)*28;
   let list_end = (page*28);
@@ -62,8 +56,7 @@ export const Apps = (req, res) => {
       appCard = appCard.replace(/AppCategories/g, categories);
       apps_list += appCard;
   }
-  // let templatesJSON = readFileSync('./templates/templates.json');
-  // let templates = JSON.parse(templatesJSON).templates;
+
 
   res.render("apps", {
     name: req.session.user,
@@ -86,6 +79,17 @@ export const Apps = (req, res) => {
 
 export const appSearch = async (req, res) => {
   let page = Number(req.params.page) || 1;
+
+  let template_param = req.params.template || 'default';
+
+  let template_file = readFileSync(`./templates/json/${template_param}.json`);
+
+  let templates = JSON.parse(template_file).templates;
+
+  templates = templates.sort((a, b) => {
+      if (a.name < b.name) { return -1; }
+  });
+  
   let list_start = (page-1)*28;
   let list_end = (page*28);
   let last_page = Math.ceil(templates.length/28);

+ 0 - 0
templates/templates.json → templates/json/default.json


+ 0 - 0
templates/foss.json → templates/json/foss.json


+ 0 - 0
templates/templates-bak.json → templates/json/templates-bak.json