Integrate flowershow packages (#923)

* [packages][m]: mv @flowershow/core package here

* [packages/core][xs]: rename to @portaljs/core

* [package.json][xs]: setup npm workspaces

* [packages/core][xs]:replace deprecated rollup executor

* [core/package.json][s]: fix mermaid versions

* [core/tsconfig][xs]: rm extends

* [core/jest.config][xs]: rm coverageDirectory

* [core/package.json][xs]: install core-js

* [packages.json][s]:use same version for all nrwl packages

* [core/.eslintrc][xs]: adjust ignorePatterns

* [core/project.json][xs]: rm publish targets

* [packages][m]: mv @flowershow/remark-wiki-link here

* [packages][m]: mv @flowershow/remark-wiki-link here

* [packages][m]: mv @flowershow/remark-embed here

* [remark-callouts/project.json][xs]: adjst test pattern

* [package.json][s]: install missing deps

* [remark-callouts][xs]: adjst fields in package.json

* [remark-callouts][s]: rm pubish targets and adjst build executor

* [remark-embed/jest.config][xs]: rm unknown option coverageDirectory

* [remark-embed][xs]: rm publish targets

* [remark-embed][s]: rename to @portaljs/remark-embed

* [remark-wiki-link/eslintrc][xs]:adjst ignorePatterns

* [package.json][xs]: install missing deps

* [remark-wiki-link/test][xs]:specify format

- also temporarily force any type on htmlExtension

* [remark-wiki-link/README][xs]: replace @flowershow with @portaljs

* [remark-wiki-link][xs]:rm old changelog

* [remark-wiki-link][xs]: adjst package.json

* [remark-wiki-link/project.json][xs]: rm publish targets

* [core][s]: rm old changelog

* [core/README][xs]:correct scope name

* [remark-callouts/README][xs]: add @portaljs to pckg name

* [remark-embed/README][xs]: add @portaljs to pckg name

* [package-lock.json][xs]: refresh after rebasing on main
This commit is contained in:
Ola Rubaj
2023-06-07 12:21:00 +02:00
committed by GitHub
parent 0b8c56bcac
commit af134cac8b
139 changed files with 10264 additions and 2303 deletions

View File

@@ -0,0 +1,60 @@
// ToC: get the html nodelist for headings
import { TocSection } from "../ui/Layout";
export function collectHeadings(nodes: NodeListOf<HTMLHeadingElement>) {
const sections: Array<TocSection> = [];
Array.from(nodes).forEach((node) => {
const { id, innerText: title, tagName: level } = node;
if (!(id && title)) {
return;
}
if (level === "H1") {
sections.push({ id, title, level, children: [] });
}
const parentSection = sections[sections.length - 1];
if (level === "H2") {
if (parentSection && level > parentSection.level) {
(parentSection as TocSection).children.push({
id,
title,
level,
children: [],
});
} else {
sections.push({ id, title, level, children: [] });
}
}
if (level === "H3") {
const subSection =
parentSection?.children[parentSection?.children?.length - 1];
if (subSection && level > subSection.level) {
(subSection as TocSection).children.push({
id,
title,
level,
children: [],
});
} else if (parentSection && level > parentSection.level) {
(parentSection as TocSection).children.push({
id,
title,
level,
children: [],
});
} else {
sections.push({ id, title, level, children: [] });
}
}
// TODO types
sections.push(...collectHeadings((node.children as any) ?? []));
});
return sections;
}

View File

@@ -0,0 +1,8 @@
export const formatDate = (date: string, locales = "en-US") => {
const options: Intl.DateTimeFormatOptions = {
year: "numeric",
month: "long",
day: "numeric",
};
return new Date(date).toLocaleDateString(locales, options);
};

View File

@@ -0,0 +1,25 @@
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const pageview = ({
url,
analyticsID,
}: {
url: string;
analyticsID: string;
}) => {
if (typeof window.gtag !== undefined) {
window.gtag("config", analyticsID, {
page_path: url,
});
}
};
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
export const event = ({ action, category, label, value }) => {
if (typeof window.gtag !== undefined) {
window.gtag("event", action, {
event_category: category,
event_label: label,
value,
});
}
};

View File

@@ -0,0 +1,2 @@
export { pageview } from "./gtag";
export { collectHeadings } from "./collectHeadings";

View File

@@ -0,0 +1,4 @@
export const nameFromUrl = (url: string) => {
const name = url.split("/").slice(-1)[0].replace("-", " ");
return name.charAt(0).toUpperCase() + name.slice(1);
};