diff --git a/packages/glow/src/glow.js b/packages/glow/src/glow.js index 46ff3fd1..3a42e0cd 100644 --- a/packages/glow/src/glow.js +++ b/packages/glow/src/glow.js @@ -79,7 +79,7 @@ function getTags(lang) { const tags = HTML_TAGS.filter(el => !el.lang || el.lang.includes(lang)) // custom keywords - if (!['yaml','html', 'json'].includes(lang)) { + if (!['yaml', 'html', 'json'].includes(lang)) { const w = SPECIAL_WORDS[lang] const words = (w ? w + '|' : '') + COMMON_WORDS const re = new RegExp(`\\b(${words})\\b`, 'gi') @@ -189,7 +189,7 @@ function renderString(str) { // exported for testing purposes -export function renderRow(row, lang, mark=true) { +export function renderRow(row, lang, mark = true) { if (!row) return '' const els = parseRow(row, lang) diff --git a/packages/nuejs/src/compile.js b/packages/nuejs/src/compile.js index c45fba62..b54e08b9 100644 --- a/packages/nuejs/src/compile.js +++ b/packages/nuejs/src/compile.js @@ -55,11 +55,11 @@ function compileNode(root) { attribs[name] = push(body, true) } - // for expression + // for expression } else if (key == ':for') { attribs[key] = push(compileLoop(val, node)) - // attributes + // attributes } else if (':$'.includes(char) && val && key != ':is') { const expr = has_expr ? arrwrap(parseExpr(val)) : setContext(val) attribs[key] = push(expr) diff --git a/packages/nuejs/src/expr.js b/packages/nuejs/src/expr.js index bc613dfd..f2a1cedb 100644 --- a/packages/nuejs/src/expr.js +++ b/packages/nuejs/src/expr.js @@ -40,7 +40,7 @@ export function parseExpr(str, is_style) { ret.push(str.includes("'") ? JSON.stringify(str) : `'${str}'`) } - // Object: { is-active: isActive() } + // Object: { is-active: isActive() } } else if (isObject(str.trim())) { const vals = parseClass(str) ret.push(...vals) @@ -104,12 +104,12 @@ export function parseFor(str) { const keys = parseKeys(prefix) return [keys.slice(0, 2), expr, keys[2] || '$index', true] - // Object deconstruction + // Object deconstruction } else if (prefix[0] == '{') { const { keys, index } = parseObjectKeys(prefix) return [keys, expr, index || '$index'] - // Normal loop variable + // Normal loop variable } else { const [key, index = '$index'] = prefix.split(/\s?,\s?/) return [key, expr, index] diff --git a/packages/nuejs/src/render.js b/packages/nuejs/src/render.js index 7f3847aa..86180bc1 100644 --- a/packages/nuejs/src/render.js +++ b/packages/nuejs/src/render.js @@ -128,7 +128,7 @@ function processIf(node, expr, data, deps) { // for function processFor(node, expr, data, deps) { - const [ $keys, for_expr, $index, is_object_loop ] = parseFor(expr) + const [$keys, for_expr, $index, is_object_loop] = parseFor(expr) // syntax error if (!for_expr) throw { @@ -151,8 +151,8 @@ function processFor(node, expr, data, deps) { return key === $keys ? (item == null ? data[key] : item) : key == $index ? items.indexOf(item) : - $keys.includes(key) ? item[key] : - data[key] + $keys.includes(key) ? item[key] : + data[key] } }) @@ -207,11 +207,11 @@ function processNode(opts) { delete attribs.client // do nothing: pass content as is - // content + // content } else if (type == 'text') { setContent(node, data) - // element + // element } else if (type == 'tag' || type == 'style' || type == 'script') { // if @@ -245,7 +245,7 @@ function processNode(opts) { if (html && html != 'false') DOM.replaceElement(node, mkdom(html)) else removeNode(node) - // slot content provided as data + // slot content provided as data } else if (data.innerHTML) { DOM.replaceElement(node, mkdom(data.innerHTML)) @@ -295,17 +295,17 @@ function getJS(nodes) { return js.join('\n') } -function createComponent(node, global_js='', template) { +function createComponent(node, global_js = '', template) { const name = getComponentName(node) // javascript const js = getJS(node.children) - const Impl = js[0] && exec(`class Impl { ${ js } }\n${global_js}`) + const Impl = js[0] && exec(`class Impl { ${js} }\n${global_js}`) // must be after getJS() const tmpl = getOuterHTML(node) - function create(data, deps=[], inner) { + function create(data, deps = [], inner) { if (Impl) data = Object.assign(new Impl(data), data) // ...spread won't work try { return processNode({ root: mkdom(tmpl), data, deps, inner }) diff --git a/packages/nuekit/src/browser/view-transitions.js b/packages/nuekit/src/browser/view-transitions.js index f99f7d2a..ce175656 100644 --- a/packages/nuekit/src/browser/view-transitions.js +++ b/packages/nuekit/src/browser/view-transitions.js @@ -52,7 +52,7 @@ export async function loadPage(path, replace_state) { dispatchEvent(new Event('route')) // route:app event - const [_, app ] = location.pathname.split('/') + const [_, app] = location.pathname.split('/') dispatchEvent(new Event(`route:${app || 'home'}`)) setActive(path) diff --git a/packages/nuekit/src/cli.js b/packages/nuekit/src/cli.js index 5abd4384..344a5234 100755 --- a/packages/nuekit/src/cli.js +++ b/packages/nuekit/src/cli.js @@ -31,15 +31,15 @@ export function getArgs(argv) { // skip if (arg.endsWith(sep + 'cli.js') || checkExecutable.test(arg) || arg == '--') { - // test suite + // test suite } else if (arg.endsWith('.test.js')) { args.test = true - // command + // command } else if (commands.includes(arg)) { args.cmd = arg - // options + // options } else if (!opt && arg[0] == '-') { // booleans @@ -119,7 +119,7 @@ async function runCommand(args) { const paths = await nue.build(args.paths) if (!dryrun && deploy && paths[0]) await deployer({ paths, root: nue.dist, init }) - // serve + // serve } else { await nue.serve() } @@ -134,11 +134,11 @@ if (esMain(import.meta)) { if (args.help) { await printHelp() - // version + // version } else if (args.version) { await printVersion() - // command + // command } else if (!args.test) { try { await runCommand(args) diff --git a/packages/nuekit/src/create.js b/packages/nuekit/src/create.js index bb26b576..16026ba7 100644 --- a/packages/nuekit/src/create.js +++ b/packages/nuekit/src/create.js @@ -42,7 +42,7 @@ export async function create({ root, name = 'simple-blog', port }) { const archive_name = join(root, `${name}-source.tar.gz`) const archive_web = `https://${name}.nuejs.org/${debug ? 'test' : 'source'}.tar.gz` const archive = await fetch(archive_web) - + // catch download issues if (archive.status != 200) return console.error(`Downloading template "${archive_web}" failed with "${archive.statusText}".`) await fs.writeFile(archive_name, Buffer.from(await archive.arrayBuffer())) diff --git a/packages/nuekit/src/init.js b/packages/nuekit/src/init.js index a00476ec..f3bb58e6 100644 --- a/packages/nuekit/src/init.js +++ b/packages/nuekit/src/init.js @@ -90,7 +90,7 @@ async function initDir({ dist, is_dev, esbuild, cwd, srcdir, outdir }) { function resolvePath(npm_path) { - const [ npm_name, ...parts ] = npm_path.split('/') + const [npm_name, ...parts] = npm_path.split('/') const module_path = dirname(fileURLToPath(resolve(npm_name, import.meta.url))) return join(module_path, ...parts) } diff --git a/packages/nuekit/src/layout/components.js b/packages/nuekit/src/layout/components.js index 1d375f94..8af734e5 100644 --- a/packages/nuekit/src/layout/components.js +++ b/packages/nuekit/src/layout/components.js @@ -1,7 +1,5 @@ import { elem, parseSize, renderInline, renderIcon } from 'nuemark' -import { readFileSync } from 'node:fs' -import { join } from 'node:path' export function renderPageList(data) { const key = data.collection_name || data.content_collection @@ -23,8 +21,8 @@ export function renderNavi(data) { return Array.isArray(items) ? renderNav({ items, icon_dir }) : typeof items == 'object' - ? renderMultiNav(items, data) - : '' + ? renderMultiNav(items, data) + : '' } function renderTOC(data) { @@ -67,15 +65,15 @@ export function renderPage(page) { const body = !thumb ? time + elem('a', { href: url }, h2 + p) - : // figure + // figure + : elem( + 'a', + { href: url }, elem( - 'a', - { href: url }, - elem( - 'figure', - elem('img', { src: thumb, loading: 'lazy' }) + elem('figcaption', time + h2 + p) - ) + 'figure', + elem('img', { src: thumb, loading: 'lazy' }) + elem('figcaption', time + h2 + p) ) + ) return elem('li', { class: isNew(date) && 'is-new' }, body) } diff --git a/packages/nuekit/src/layout/head.js b/packages/nuekit/src/layout/head.js index 345509aa..8ee2ab47 100644 --- a/packages/nuekit/src/layout/head.js +++ b/packages/nuekit/src/layout/head.js @@ -26,7 +26,7 @@ export function renderHead(data) { is_prod, } = data - const { scripts=[], styles=[], inline_css=[], components=[] } = data.assets || {} + const { scripts = [], styles = [], inline_css = [], components = [] } = data.assets || {} const head = [``] if (title) head.push(elem('title', title_template.replace(/%s/gi, title))) @@ -76,7 +76,7 @@ export function renderHead(data) { const css = inline_css.map(el => el.css).join('') head.push(elem('style', css)) - // dev mode: keep path info for hot-reloading + // dev mode: keep path info for hot-reloading } else { inline_css.forEach(el => head.push(elem('style', { href: base + el.path }, el.css))) } diff --git a/packages/nuekit/src/layout/page.js b/packages/nuekit/src/layout/page.js index baabe5d0..f2e988c1 100644 --- a/packages/nuekit/src/layout/page.js +++ b/packages/nuekit/src/layout/page.js @@ -5,6 +5,7 @@ import { getLayoutComponents, renderPageList } from './components.js' import { renderHead } from './head.js' + const SLOTS = 'head banner header subheader pagehead pagefoot aside beside footer bottom main'.split(' ') const MAIN = parseNue(` @@ -54,7 +55,7 @@ export function getSPALayout(body, data) { return ltrim(` - ${ renderHead(data) } + ${renderHead(data)} @@ -101,7 +102,7 @@ function convertToTags(components, data) { const tags = {} components.forEach(comp => { - const { name } = comp + const { name } = comp || {} if (name && comp.render && !SLOTS.includes(name)) { tags[name] = function(data) { @@ -114,9 +115,8 @@ function convertToTags(components, data) { return tags } - -export function renderPage(data, lib, custom_tags={}) { - const comps = [ ...lib, ...getLayoutComponents()] +export function renderPage(data, lib, custom_tags = {}) { + const comps = [...lib, ...getLayoutComponents()] const { document } = data const tags = { @@ -127,7 +127,7 @@ export function renderPage(data, lib, custom_tags={}) { } // nuemark opts: { data, sections, heading_ids, links, tags } - const { heading_ids, sections, content_wrapper, links } = data + const { heading_ids, sections, content_wrapper, links } = data const content = document.render({ data, heading_ids, sections, content_wrapper, links, tags }) const slots = renderSlots({ ...data, content }, comps) diff --git a/packages/nuekit/src/nuefs.js b/packages/nuekit/src/nuefs.js index ff3e54a9..b75da8c3 100644 --- a/packages/nuekit/src/nuefs.js +++ b/packages/nuekit/src/nuefs.js @@ -84,9 +84,9 @@ export async function fswatch(root, callback, onremove) { } -export async function fswalk(opts, _dir='', _ret=[]) { +export async function fswalk(opts, _dir = '', _ret = []) { if (typeof opts == 'string') opts = { root: opts } - const { root, symdirs=true } = opts + const { root, symdirs = true } = opts const files = await fs.readdir(join(root, _dir), { withFileTypes: true }) @@ -105,7 +105,7 @@ export async function fswalk(opts, _dir='', _ret=[]) { const IGNORE = ['node_modules', 'functions', 'package.json', 'bun.lockb', 'pnpm-lock.yaml', 'README.md'] -function ignore(name='') { +function ignore(name = '') { return '._'.includes(name[0]) || IGNORE.includes(name) } diff --git a/packages/nuekit/src/nuekit.js b/packages/nuekit/src/nuekit.js index 460c62ab..5ef275de 100644 --- a/packages/nuekit/src/nuekit.js +++ b/packages/nuekit/src/nuekit.js @@ -59,7 +59,7 @@ export async function createKit(args) { const arr = [] for (const path of paths) { if (!path.startsWith('/@nue')) { - const { css } = await processCSS({ path, ...parsePath(path)}) + const { css } = await processCSS({ path, ...parsePath(path) }) arr.push({ path, css }) } } @@ -147,10 +147,10 @@ export async function createKit(args) { if (html.includes(' { const dpath = join(dist, path) await fs.rm(dpath, { recursive: true, force: true }) diff --git a/packages/nuekit/src/site.js b/packages/nuekit/src/site.js index a1bb142a..59a2246b 100644 --- a/packages/nuekit/src/site.js +++ b/packages/nuekit/src/site.js @@ -91,7 +91,7 @@ export async function createSite(args) { } async function getModel() { - const { src, namespace='app' } = site_data.server_model || {} + const { src, namespace = 'app' } = site_data.server_model || {} if (src) { const model = await loadExtension(src) log('Loaded model from', src) @@ -263,7 +263,7 @@ export async function createSite(args) { self.getData = async function(pagedir) { const data = { nuekit_version, ...site_data, is_prod } - for (const dir of [ ...self.globals, ...traverseDirsUp(pagedir)]) { + for (const dir of [...self.globals, ...traverseDirsUp(pagedir)]) { extendData(data, await readDirData(dir)) } return data diff --git a/packages/nuemark/src/parse-document.js b/packages/nuemark/src/parse-document.js index 4b0a4008..110be91b 100644 --- a/packages/nuemark/src/parse-document.js +++ b/packages/nuemark/src/parse-document.js @@ -25,7 +25,7 @@ export function parseDocument(lines) { meta.description = block?.content[0] } - const sections = sectionize(blocks) || [ blocks ] + const sections = sectionize(blocks) || [blocks] function renderSections(opts) { const classList = Array.isArray(opts.sections) ? opts.sections : [] @@ -40,14 +40,14 @@ export function parseDocument(lines) { } return { - render(opts={}) { + render(opts = {}) { Object.assign(things.reflinks, parseReflinks(opts.links)) opts = { ...opts, ...things } const html = opts.sections ? renderSections(opts) : renderBlocks(blocks, opts) return html + renderFootnotes(things.footnotes) }, - renderTOC(attr={}) { + renderTOC(attr = {}) { const navs = sections.map(renderNav).join('\n').trim() return elem('div', { class: attr.class }, navs) }, @@ -64,7 +64,7 @@ export function parseDocument(lines) { } } -export function sectionize(blocks=[]) { +export function sectionize(blocks = []) { const arr = [] let section @@ -91,7 +91,7 @@ export function sectionize(blocks=[]) { function renderFootnotes(arr) { if (!arr.length) return '' - const html = arr.map(el => elem('li', elem('a', { name: el.key }) + renderInline(el.value) )) + const html = arr.map(el => elem('li', elem('a', { name: el.key }) + renderInline(el.value))) return elem('ol', { role: 'doc-endnotes' }, html.join('\n')) } @@ -102,7 +102,7 @@ function renderNav(blocks) { const links = headings.map(h => { const id = h.attr.id || createHeadingId(h.text) const label = h.level == 2 ? elem('strong', h.text) : h.text - return elem('a', { href: `#${ id }` }, label) + return elem('a', { href: `#${id}` }, label) }) return links[0] ? elem('nav', links.join('\n')) : '' @@ -134,7 +134,7 @@ export function stripMeta(lines) { return parseYAML(front) } -function parseReflinks(links={}) { +function parseReflinks(links = {}) { for (const key in links) { const href = links[key] if (typeof href == 'string') links[key] = parseLinkTitle(href) diff --git a/packages/nuemark/src/parse-inline.js b/packages/nuemark/src/parse-inline.js index 3092c370..c285eb79 100644 --- a/packages/nuemark/src/parse-inline.js +++ b/packages/nuemark/src/parse-inline.js @@ -4,8 +4,8 @@ import { parseTag, parseAttr } from './parse-tag.js' export const FORMATTING = { - '***': 'EM', - '___': 'EM', + '***': 'EM', + '___': 'EM', '**': 'strong', '__': 'strong', @@ -115,9 +115,9 @@ const PARSERS = [ if (i == -1) return { text: c } const name = str.slice(1, i).trim() - return '.#'.includes(name[0]) ? { is_attr: true, attr: parseAttr(name), end: i + 1 } : - { is_var: true, name, end: i + 1 } - ; + return '.#'.includes(name[0]) + ? { is_attr: true, attr: parseAttr(name), end: i + 1 } + : { is_var: true, name, end: i + 1 } } }, @@ -145,7 +145,7 @@ function isValidName(name) { export function parseInline(str) { const tokens = [] - while(str) { + while (str) { for (const fn of PARSERS) { const item = fn(str, str[0]) if (item) { @@ -193,7 +193,7 @@ export function parseLink(str, is_reflink) { j = str.indexOf(close, i + 2) if (i == -1 || j == -1) return - } else { + } else { // links with closing bracket (ie. Wikipedia) if (str[j + 1] == ')') j++ } @@ -203,7 +203,10 @@ export function parseLink(str, is_reflink) { // footnote reference const is_footnote = href[0] == '^' - if (is_footnote) { is_reflink = null; href = '#' + href } + if (is_footnote) { + is_reflink = null + href = '#' + href + } return { href, title, label, diff --git a/packages/nuemark/src/render-inline.js b/packages/nuemark/src/render-inline.js index c5597420..cc41e959 100644 --- a/packages/nuemark/src/render-inline.js +++ b/packages/nuemark/src/render-inline.js @@ -3,20 +3,20 @@ import { parseInline, ESCAPED } from './parse-inline.js' import { renderTag } from './render-tag.js' import { elem } from './render-blocks.js' -export function renderToken(token, opts={}) { - const { data={} } = opts +export function renderToken(token, opts = {}) { + const { data = {} } = opts const { text } = token return text ? text : token.is_format ? formatText(token, opts) : - token.is_var ? renderVariable(token.name, data) : - token.is_image ? renderImage(token) : - token.is_tag ? renderTag(token, opts) : - token.href ? renderLink(token, opts) : - '' + token.is_var ? renderVariable(token.name, data) : + token.is_image ? renderImage(token) : + token.is_tag ? renderTag(token, opts) : + token.href ? renderLink(token, opts) : + '' } -function formatText({tag, body }, opts) { +function formatText({ tag, body }, opts) { const html = tag == 'code' ? renderCode(body) : renderInline(body, opts) return tag == 'EM' ? elem('em', elem('strong', html)) : elem(tag, html) } @@ -32,7 +32,7 @@ function renderImage(img) { function renderLink(link, opts) { const { is_footnote, href, title } = link - const { reflinks={}, noterefs=[] } = opts + const { reflinks = {}, noterefs = [] } = opts const url = reflinks[href] || { href } let label = renderInline(link.label, opts) diff --git a/packages/nuemark/src/render-tag.js b/packages/nuemark/src/render-tag.js index 69ad6536..1be0ff93 100644 --- a/packages/nuemark/src/render-tag.js +++ b/packages/nuemark/src/render-tag.js @@ -1,6 +1,6 @@ -import { renderBlocks, renderContent } from './render-blocks.js' -import { sectionize, } from './parse-document.js' +import { renderBlocks } from './render-blocks.js' +import { sectionize } from './parse-document.js' import { renderInline } from './render-inline.js' import { elem } from './render-blocks.js' import { readFileSync } from 'node:fs' @@ -55,7 +55,7 @@ const TAGS = { image() { const { attr, data } = this - const { caption, href, loading='lazy' } = data + const { caption, href, loading = 'lazy' } = data const src = data.src || data._ || data.large const alt = data.alt || caption @@ -140,7 +140,7 @@ export function renderIcon(name, symbol, icon_dir) { } -export function renderTag(tag, opts={}) { +export function renderTag(tag, opts = {}) { const tags = { ...TAGS, ...opts.tags } const fn = tags[tag.name || 'block'] @@ -186,13 +186,13 @@ const MIME = { mp4: 'video/mp4', } -function getMimeType(path='') { +function getMimeType(path = '') { const type = path.slice(path.lastIndexOf('.') + 1) return MIME[type] || `image/${type}` } export function createPicture(img_attr, data) { - const { small, offset=750 } = data + const { small, offset = 750 } = data const sources = [small, img_attr.src].map(src => { const prefix = src == small ? 'max' : 'min' @@ -209,8 +209,8 @@ function getListItems(arr) { } export function parseSize(data) { - const { size='' } = data - const [ w, h ] = size.trim().split(/\s*\D\s*/) + const { size = '' } = data + const [w, h] = size.trim().split(/\s*\D\s*/) return { width: w || data.width, height: h || data.height } } @@ -243,7 +243,7 @@ export function wrap(name, html) { function getInnerHTML(blocks = [], opts) { - const [ first, second ] = blocks + const [first, second] = blocks if (!first) return '' const { content } = first return content && !second ? renderInline(content.join(' '), opts) : renderBlocks(blocks, opts) @@ -252,7 +252,7 @@ function getInnerHTML(blocks = [], opts) { // table helpers export function renderTable(table, opts) { - const { rows, attr, head=true } = table + const { rows, attr, head = true } = table if (!rows) return '' // column count @@ -290,7 +290,7 @@ export function parseTable(lines) { if (line.startsWith('---')) { if (rows.length == 1) specs.head = true - else if (i == lines.length -2) specs.foot = true + else if (i == lines.length - 2) specs.foot = true return } @@ -300,7 +300,7 @@ export function parseTable(lines) { // append to previous row if (els.length < specs.cols) { - const prev = rows[rows.length -1] + const prev = rows[rows.length - 1] if (prev.length < specs.cols) return prev.push(...els) }