Changeset d9ad6c5 in Klonkt for src/middleware
- Timestamp:
- 07/28/2026 06:17:36 PM (6 weeks ago)
- Branches:
- main
- Children:
- a7bcf66
- Parents:
- 2708282
- File:
-
- 1 edited
-
src/middleware/render.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/middleware/render.js
r2708282 rd9ad6c5 37 37 const __dirname = path.dirname(fileURLToPath(import.meta.url)); 38 38 const VIEWS_DIR = path.join(__dirname, '..', 'views'); 39 40 /** 41 * Render a post body to an HTML string with the SAME partial de Krant uses. 42 * 43 * For surfaces that are not an EJS page: the Guardian PWA builds its cards in 44 * the browser, so it gets the finished HTML in its state blob instead of the 45 * raw columns. One renderer, so a post cannot drift into looking different 46 * depending on where you run into it. 47 */ 48 export function renderNoteBody(nb, lang) { 49 if (!nb || !nb.content) return ''; 50 const _l = lang || 'nl'; 51 // ejs.renderFile hands back a Promise even with async:false, and the callers 52 // here are plain synchronous route code. Compile the file ourselves instead; 53 // `filename` is what lets the partial's own relative includes resolve. 54 const file = path.join(VIEWS_DIR, 'partials', 'note-body.ejs'); 55 try { 56 return ejs.render(fs.readFileSync(file, 'utf8'), { 57 nb, 58 t: (key, vars) => i18nT(_l, key, vars), 59 emojiHtml, 60 emojiName, 61 noteQuote: parseQuote, 62 thumb: (url, w) => (typeof url === 'string' && /^https?:\/\//i.test(url) ? imgProxyUrl(url, w || 480) : url), 63 avatar: (url, w) => (typeof url === 'string' && /^https?:\/\//i.test(url) ? imgProxyUrl(url, w || 128) : url), 64 }, { filename: file, async: false }); 65 } catch (e) { 66 console.warn('[render] note body failed:', e.message); 67 return ''; 68 } 69 } 39 70 40 71 // App version (from package.json) + short commit hash (from .klonkt-version, written by
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)