mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
- The General/ level is gone: its 109 files moved up into the folders of the same name, and its topic table is the "Shared topics" section of Features.md. - Accessibility is one folder, docs/Features/Accessibility/, with the Admin Panel's accessibility page in it. - Every folder's main page is README.md (110 X/X.md pages renamed with git mv, five merged with an existing README.md, 26 index pages added for folders that had none), so a folder opened on GitHub shows its page. - The 73 "# Moved" forwarding pages are deleted, with the folders that held only them; every link that went to one goes to its final page. - docs/Features/README.md has the website's "Features in WeKan" overview, each feature linking to its page here. 1,129 Markdown links in 262 files and 352 doc paths in code, tests, compose, snap and release files follow. tests/docsFeaturesLayout.test.cjs fails when General/ or a "# Moved" page comes back, a folder has no README.md, or a relative link in the docs or README.md does not resolve. Thanks to xet7 !
70 lines
3.6 KiB
JavaScript
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/README.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 };
|