1 2 import * as template from "./topic-template.js" 3import { getAbsoluteUrlForLang, getAvailableLangs, getPathWithLang, normalizeLang } from "../i18n/i18n.js"; 4 5 let { addViewRoute, ajax, escapeHtml, doOnAllSites, session, t } = typeof window !== 'undefined' 6 ? await import("../../shared/frontend.js") 7 : await import("../../shared/backend-server.js") 8 9 10addViewRoute("/topicdraft", async (param)=>{ 11 return {content:"<s-topic-draftlist></s-topic-draftlist>" , title:t("topic drafts")} 12}) 13 14addViewRoute("/topicdraft/:id", async (param)=>{ 15 return {content:`<s-topic-edit draftId=${param.id||''}></s-topic-edit>`, title:t("topic drafts")} 16}) 17 18addViewRoute("/topic/:id", async (param)=>{ 19 //console.log(param) 20 let data = await ajax("GET", `/api/topic/item/${param.id}`) 21 if (!data) return 404 22 if (process) { 23 session.res.writeHead(301, { 'Location': getPathWithLang(`/${data.section}/${data.slug}`, session.lang, session.settings) }); 24 session.res.end(); 25 return "ok" 26 } else { 27 history.replaceState({}, '', getPathWithLang(`/${data.section}/${data.slug}`, session.lang, session.settings)) 28 } 29}) 30 31 32 33//console.log(settings) 34doOnAllSites(()=>{ 35 let secList = Object.keys(session.settings.sections) 36 secList.forEach((sec)=>{ 37 for (let cat in session.settings.sections[sec].categories ) { 38 let s = sec 39 let catSet = session.settings.sections[sec].categories[cat] 40 //cat Ð¼Ð¾Ð¶ÐµÑ Ð±ÑÑÑ Ð¿ÑÑÑой ÑÑоÑокой '' ÑÑо ноÑм =) 41 if (catSet.template) { 42 addViewRoute(`/${s}/:slug${cat?`/${cat}`:''}`, async (param)=>{ 43 let data = await ajax("GET", `/api/topic/section/${s}/${param.slug}`) 44 if (!data) return 404 45 let filter = structuredClone(catSet.filter) 46 for(let i in filter) { 47 filter[i] = filter[i].replace(/\$_id/g, data._id) 48 } 49 if (process) { 50 const pageLang = normalizeLang(session.lang) 51 const titleByLang = (data?.title && typeof data.title === "object" && !Array.isArray(data.title)) ? data.title : {} 52 const sourceLang = normalizeLang(data?.sourceLang || "en") 53 const hasTitleForLang = typeof titleByLang?.[pageLang] === "string" && titleByLang[pageLang].trim() !== "" 54 const hasSourceTitle = typeof titleByLang?.[sourceLang] === "string" && titleByLang[sourceLang].trim() !== "" 55 if (!hasTitleForLang && !hasSourceTitle) { 56 session.res.statusCode = 404 57 } 58 session.res.setHeader('Last-Modified', data?.updated.toUTCString()); 59 } 60 const path = `/${s}/${data.slug}${cat ? `/${cat}` : ''}` 61 const langs = getAvailableLangs(session.settings) 62 const contentByLang = (data?.content && typeof data.content === "object" && !Array.isArray(data.content)) ? data.content : {} 63 const alternates = Object.fromEntries( 64 langs 65 .filter((lang) => typeof contentByLang?.[lang] === "string" && contentByLang[lang].trim() !== "") 66 .map((lang) => [lang, getAbsoluteUrlForLang(session.baseUrl, lang, path, session.settings)]) 67 ) 68 69 return { 70 content: await template[catSet.template](data, filter ), 71 title:`${catSet.name2 ? `${t(catSet.name2)} ` : ""}${t(data.title)}`, 72 description:`${t(catSet.name)} ${t(data.title)} | ${t(data?._aidescription)}`, 73 alternates, 74 sourceLang: data?.sourceLang, 75 } 76 }) 77 } 78 } 79 }) 80 81 secList.forEach((slug)=>{ 82 if (session.settings.sections[slug].type=='topic') { 83 addViewRoute( "/"+slug, async (param) => { 84 if (!session.settings.sections[slug]) return 404; 85 86 let html = '' 87 if (process) { 88 const { flowSSR } = await import( "../element/element-server.js") 89 //console.log(session.settings.sections[slug]) 90 html = await flowSSR ({ 91 type:session.settings.sections[slug].type, 92 label:t(session.settings.sections[slug].name), 93 filter:{section:slug}, 94 order:session.settings.sections[slug].defaultFilter?.order 95 }) 96 } 97 /* 98 if (session.settings.sections[slug].type=='post') { 99 return {content: `<s-post-flow type=post section=${slug}>${html}</s-post-flow>`, title:session.settings.sections[slug].name} 100 } 101 */ 102 //if (session.settings.sections[slug].type=='topic') { 103 return { 104 content:`<s-topic-flow type=topic section=${slug}>${html}</s-topic-flow>`, 105 title:t(session.settings.sections[slug].name), 106 description:t(session.settings.sections[slug].description) 107 } 108 //} 109 110 }) 111 } 112 }) 113})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.