Files
wekan/models/lib/websiteView.js
T
Lauri Ojansivu 2e8549032e Website: import and export WordPress, Ghost, Blogger, static and HTML sites, and the board as a website at a public board's address.
Import and Export have a new group, Website:

- WordPress (.xml): WordPress eXtended RSS from Tools -> Export, as
  Squarespace, Wix and others also write it; written as WordPress reads it.
- WordPress REST API (.json): /wp-json/wp/v2/posts and /pages.
- Ghost: its JSON export, written as Ghost's importer reads it.
- Blogger (.xml): its Atom backup.
- Hugo, Jekyll, Eleventy, Astro (.zip): Markdown files with YAML or TOML
  front matter, and their images; written as content/pages and
  content/posts.
- HTML website, Medium (.zip): a site's .html pages and images, read for
  their main text; written as the published site itself, ready for any
  web server, with the cards' attachments beside their pages.
- Substack (.zip): posts.csv and the posts' HTML.

Each page and post becomes a card in the list of its status (Published,
Draft, Pending review, Scheduled, Private), pages in the swimlane Pages and
posts in Posts, its content as Markdown, a subpage as a subtask, categories
and tags as labels, approved comments as comments, a .zip's images as
attachments. A site's HTML is read as text, so no script of it reaches a
card; a card's text is written into an exported site escaped, never as
markup.

Board View / Website shows the board as that website: the cards of its
Published list (every list when it has none), Pages as the menu with the
subpages, the other cards as posts, newest first, and the cards'
attachments - built straight from the board. As a public board's default
view in Board Settings / Board View, it is what visitors see at the
board's address instead of the kanban; a draft is never shown, not even by
its id. Admin Panel / Features can turn it off.

The Sandstorm WordPress and Hacker CMS grain imports stay under Sandstorm,
by the rule that a platform's apps are listed under it.

12 new strings are translated in every language. Lower-confidence
translations: ace, ak, ay, bi, bm, bo, dz, ee, chr, bua, cv, ba, csb, an,
co, br, ary, bho, as, am, ckb, iu, kl, ff, fj, gn, gv, kw, ig, ha, haw, ks,
kok, fur, hsb, fo, ku, lld, nah, rup, sah, se, sc, scn, nap, qu, sm, pap,
lg, nd, ss, nso, rn, om, mg, ny, sn, so, ps, sd, mai, or_IN, my, la, tig,
wal, tlh, vo, zgh and ve-PP.

Thanks to xet7 !
2026-11-21 23:44:34 +02:00

70 lines
3.6 KiB
JavaScript

'use strict';
// Board View / Website (docs/Features/Board-Sidebar/Board-Settings/Board-View.md,
// docs/Features/Board-Sidebar/Board-Settings/Import-Export/Website/Website.md): the
// board as the website it was imported from - or one written on it - built
// straight from its lists, swimlanes, cards and attachments. Chosen as the
// board's public view in Board Settings / Board View, it is what a visitor
// sees at the public board's address instead of the kanban.
//
// on the site the cards of a list named Published (any language
// models/lib/websiteFormat.js knows), or of every list when
// the board has none; never an archived card
// pages the cards of a swimlane named Pages, in board order, a
// subtask under its parent card - the menu
// posts every other card, newest first - the front page
// content the card's description (Markdown), its attachments its
// images and files
//
// Pure, no Meteor: tests/websiteView.test.cjs.
const PUBLISHED = /^(published|publish|public|live|julkaistu|julkinen|veröffentlicht|publié|publicado|pubblicato)$/i;
const PAGES = /^(pages?|sivut|seiten|pagine|páginas)$/i;
const str = value => (typeof value === 'string' ? value : '');
const time = value => {
const t = value ? new Date(value).getTime() : NaN;
return Number.isFinite(t) ? t : 0;
};
/**
* @param {Object} board { lists: [{ _id, title, sort }], swimlanes: [{ _id, title }],
* cards: [{ _id, title, listId, swimlaneId, sort, parentId, archived, createdAt, receivedAt, startAt }] }
* @returns {{ pages, posts, home, byId }}
*/
function websiteOf({ lists = [], swimlanes = [], cards = [] } = {}) {
const published = lists.filter(l => l && !l.archived && PUBLISHED.test(str(l.title).trim())).map(l => l._id);
const onSite = new Set(published.length ? published : lists.filter(l => l && !l.archived).map(l => l._id));
const pageLanes = new Set(swimlanes.filter(s => s && PAGES.test(str(s.title).trim())).map(s => s._id));
const listSort = new Map(lists.map(l => [l._id, Number(l.sort) || 0]));
const visible = cards.filter(c => c && !c.archived && onSite.has(c.listId));
const ids = new Set(visible.map(c => c._id));
const bySort = (a, b) => (listSort.get(a.listId) - listSort.get(b.listId)) || ((Number(a.sort) || 0) - (Number(b.sort) || 0))
|| str(a.title).localeCompare(str(b.title));
const pageCards = visible.filter(c => pageLanes.has(c.swimlaneId)).sort(bySort);
// The menu: top-level pages, each with the pages under it.
const pages = pageCards.filter(c => !c.parentId || !ids.has(c.parentId)).map(c => ({
_id: c._id, title: str(c.title),
children: pageCards.filter(x => x.parentId === c._id).map(x => ({ _id: x._id, title: str(x.title) })),
}));
const when = c => time(c.receivedAt) || time(c.startAt) || time(c.createdAt);
const posts = visible.filter(c => !pageLanes.has(c.swimlaneId))
.sort((a, b) => when(b) - when(a) || bySort(a, b))
.map(c => ({ _id: c._id, title: str(c.title), date: when(c) ? new Date(when(c)).toISOString().slice(0, 10) : '' }));
return {
pages,
posts,
// The front page: the posts, or - on a site of pages only - the first page.
home: posts.length ? { posts: true } : (pages[0] ? { cardId: pages[0]._id } : { empty: true }),
byId: new Set(visible.map(c => c._id)),
};
}
// The card the address asks for, when it is on the site; otherwise the front
// page. A card that is not on the site - a draft - is never shown by its id.
function pageFor(site, cardId) {
return cardId && site.byId.has(cardId) ? { cardId } : site.home;
}
module.exports = { websiteOf, pageFor };