mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-10-22 15:05:50 +00:00
Add Children "only, includeFolders, reverse" flags, add document unhideSelf (#209)
This commit is contained in:
parent
4fa94b50d0
commit
fa241c0f61
@ -51,6 +51,7 @@ exports.onCreateNode = async ({ node, getNode, getNodesByType, actions, createNo
|
|||||||
const docTitle = fileToTitle(fileTitle);
|
const docTitle = fileToTitle(fileTitle);
|
||||||
const slug = createSlug(filePath, version);
|
const slug = createSlug(filePath, version);
|
||||||
const parentSlug = `${path.resolve(slug, '../')}/`;
|
const parentSlug = `${path.resolve(slug, '../')}/`;
|
||||||
|
const unhideSelf = false;
|
||||||
|
|
||||||
const docData = {
|
const docData = {
|
||||||
isIndex,
|
isIndex,
|
||||||
@ -58,6 +59,7 @@ exports.onCreateNode = async ({ node, getNode, getNodesByType, actions, createNo
|
|||||||
fileTitle,
|
fileTitle,
|
||||||
slug,
|
slug,
|
||||||
parentSlug,
|
parentSlug,
|
||||||
|
unhideSelf,
|
||||||
...node.frontmatter,
|
...node.frontmatter,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,33 +38,40 @@ const createList = (children: SilverstripeDocument[]): ReactElement[] => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const ChildrenOf: StatelessComponent<ChildrenOfProps> = ({ folderName, exclude, currentNode, asList }) => {
|
const ChildrenOf: StatelessComponent<ChildrenOfProps> = ({ folderName, exclude, only, currentNode, asList, includeFolders, reverse }) => {
|
||||||
if (!currentNode) {
|
if (!currentNode) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
let children: ReactElement[] = [];
|
|
||||||
if (!folderName && !exclude) {
|
var nodes: SilverstripeDocument[] = [];
|
||||||
const sourceNodes = currentNode.isIndex ? getChildren(currentNode, false) : getSiblings(currentNode)
|
|
||||||
children = asList ? createList(sourceNodes) : createCards(sourceNodes);
|
if (!folderName && !exclude && !only) {
|
||||||
|
nodes = currentNode.isIndex ? getChildren(currentNode, false) : getSiblings(currentNode)
|
||||||
|
|
||||||
} else if (folderName) {
|
} else if (folderName) {
|
||||||
const targetFolder = getChildren(currentNode, true).find(
|
const targetFolder = getChildren(currentNode, true).find(
|
||||||
child => child.isIndex && child.fileTitle.toLowerCase() === folderName.toLowerCase()
|
child => child.isIndex && child.fileTitle.toLowerCase() === folderName.toLowerCase()
|
||||||
);
|
);
|
||||||
if (targetFolder) {
|
if (targetFolder) {
|
||||||
children = asList
|
nodes = getChildren(targetFolder, false);
|
||||||
? createList(getChildren(targetFolder, false))
|
|
||||||
: createCards(getChildren(targetFolder, false));
|
|
||||||
} else {
|
|
||||||
children = [];
|
|
||||||
}
|
}
|
||||||
} else if (exclude) {
|
} else if (exclude) {
|
||||||
const exclusions = exclude.split(',').map(e => e.toLowerCase());
|
const exclusions = exclude.split(',').map(e => e.toLowerCase());
|
||||||
const nodes = getChildren(currentNode, false).filter(
|
nodes = getChildren(currentNode, includeFolders).filter(
|
||||||
child => !exclusions.includes(child.fileTitle.toLowerCase())
|
child => !exclusions.includes(child.fileTitle.toLowerCase())
|
||||||
);
|
);
|
||||||
children = asList ? createList(nodes) : createCards(nodes);
|
} else if (only) {
|
||||||
|
const inclusions = only.split(',').map(e => e.toLowerCase());
|
||||||
|
nodes = getChildren(currentNode, includeFolders).filter(
|
||||||
|
child => inclusions.includes(child.fileTitle.toLowerCase())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reverse) {
|
||||||
|
nodes.reverse();
|
||||||
|
}
|
||||||
|
let children: ReactElement[] = asList ? createList(nodes) : createCards(nodes);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="docs-overview py-5">
|
<div className="docs-overview py-5">
|
||||||
{asList &&
|
{asList &&
|
||||||
|
@ -33,6 +33,7 @@ export interface SilverstripeDocument {
|
|||||||
iconBrand?: string;
|
iconBrand?: string;
|
||||||
hideChildren?: boolean;
|
hideChildren?: boolean;
|
||||||
hideSelf?: boolean;
|
hideSelf?: boolean;
|
||||||
|
unhideSelf?: boolean;
|
||||||
parentSlug: string;
|
parentSlug: string;
|
||||||
summary: string;
|
summary: string;
|
||||||
fileTitle: string;
|
fileTitle: string;
|
||||||
@ -48,6 +49,9 @@ export interface HierarchyQuery {
|
|||||||
export interface ChildrenOfProps {
|
export interface ChildrenOfProps {
|
||||||
folderName?: string;
|
folderName?: string;
|
||||||
exclude?: string;
|
exclude?: string;
|
||||||
|
only?: string;
|
||||||
currentNode: SilverstripeDocument | null;
|
currentNode: SilverstripeDocument | null;
|
||||||
asList?: boolean;
|
asList?: boolean;
|
||||||
|
includeFolders?: boolean;
|
||||||
|
reverse?: boolean;
|
||||||
};
|
};
|
||||||
|
@ -31,6 +31,7 @@ const getNodes = (): SilverstripeDocument[] => {
|
|||||||
icon
|
icon
|
||||||
iconBrand
|
iconBrand
|
||||||
hideChildren
|
hideChildren
|
||||||
|
unhideSelf
|
||||||
slug
|
slug
|
||||||
parentSlug
|
parentSlug
|
||||||
fileTitle
|
fileTitle
|
||||||
@ -87,6 +88,8 @@ const getNavChildren = (node: SilverstripeDocument): SilverstripeDocument[] => {
|
|||||||
children = getChildren(node, true).filter(n => !n.hideSelf);
|
children = getChildren(node, true).filter(n => !n.hideSelf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getChildren(node, true).filter(n => n.unhideSelf).forEach(c => children.push(c));
|
||||||
|
|
||||||
navChildrenMap.set(node.slug, children);
|
navChildrenMap.set(node.slug, children);
|
||||||
|
|
||||||
return navChildrenMap.get(node.slug);
|
return navChildrenMap.get(node.slug);
|
||||||
|
@ -9,23 +9,38 @@ import { getCurrentNode } from '../utils/nodes';
|
|||||||
const parseChildrenOf = (data: any): ReactElement|false => {
|
const parseChildrenOf = (data: any): ReactElement|false => {
|
||||||
const currentNode = getCurrentNode();
|
const currentNode = getCurrentNode();
|
||||||
let matches;
|
let matches;
|
||||||
matches = data.match(/\[CHILDREN(\sasList)?\]/);
|
|
||||||
if (matches) {
|
|
||||||
const asList = !!matches[1];
|
|
||||||
return createElement(ChildrenOf, { currentNode, asList })
|
|
||||||
}
|
|
||||||
|
|
||||||
matches = data.match(/\[CHILDREN Folder="?([A-Za-z0-9_<>\/]+)"?.*?\]/);
|
matches = data.match(/\[CHILDREN Folder="?([A-Za-z0-9_<>\/]+)"?.*?\]/);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
const folderName = matches[1].replace(/<\/?em>/g, '_');
|
const folderName = matches[1].replace(/<\/?em>/g, '_');
|
||||||
const asList = matches[0].match(' asList');
|
const asList = matches[0].match(' asList');
|
||||||
return createElement(ChildrenOf, { folderName, currentNode, asList })
|
const includeFolders = matches[0].match(' includeFolders');
|
||||||
|
const reverse = matches[0].match(' reverse');
|
||||||
|
return createElement(ChildrenOf, { folderName, currentNode, asList, includeFolders, reverse })
|
||||||
}
|
}
|
||||||
matches = data.match(/\[CHILDREN Exclude="?([A-Za-z0-9_,]+)"?.*?\]/);
|
matches = data.match(/\[CHILDREN Exclude="?([A-Za-z0-9_,]+)"?.*?\]/);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
const asList = matches[0].match(' asList');
|
const asList = matches[0].match(' asList');
|
||||||
|
const includeFolders = matches[0].match(' includeFolders');
|
||||||
|
const reverse = matches[0].match(' reverse');
|
||||||
const exclude = matches[1].replace(/<\/?em>/g, '_');
|
const exclude = matches[1].replace(/<\/?em>/g, '_');
|
||||||
return createElement(ChildrenOf, { exclude, currentNode, asList })
|
return createElement(ChildrenOf, { exclude, currentNode, asList, includeFolders, reverse })
|
||||||
|
}
|
||||||
|
matches = data.match(/\[CHILDREN Only="?([A-Za-z0-9_,]+)"?.*?\]/);
|
||||||
|
if (matches) {
|
||||||
|
const asList = matches[0].match(' asList');
|
||||||
|
const includeFolders = matches[0].match(' includeFolders');
|
||||||
|
const reverse = matches[0].match(' reverse');
|
||||||
|
const only = matches[1].replace(/<\/?em>/g, '_');
|
||||||
|
return createElement(ChildrenOf, { only, currentNode, asList, includeFolders, reverse })
|
||||||
|
}
|
||||||
|
matches = data.match(/\[CHILDREN(\sasList)?.*?\]/);
|
||||||
|
if (matches) {
|
||||||
|
const asList = !!matches[1];
|
||||||
|
const includeFolders = matches[0].match(' includeFolders');
|
||||||
|
const reverse = matches[0].match(' reverse');
|
||||||
|
|
||||||
|
return createElement(ChildrenOf, { currentNode, asList, includeFolders, reverse })
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user