mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
Add 'packages/share-theme/' from commit '2cdd2a0a543f0bced8284ca55bc94efadbc7c91f'
git-subtree-dir: packages/share-theme git-subtree-mainline: d8f0709bce891a8ebc0676bb3b6b5314bf78a129 git-subtree-split: 2cdd2a0a543f0bced8284ca55bc94efadbc7c91f
This commit is contained in:
commit
eea3163f51
94
packages/share-theme/.eslintrc
Normal file
94
packages/share-theme/.eslintrc
Normal file
@ -0,0 +1,94 @@
|
||||
{
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended-type-checked",
|
||||
"plugin:@typescript-eslint/stylistic-type-checked"
|
||||
],
|
||||
"env": {
|
||||
"es2020": true,
|
||||
"browser": true
|
||||
},
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"ignorePatterns": ["legacy/", "dist/"],
|
||||
"parserOptions": {
|
||||
"project": ["./tsconfig.eslint.json"],
|
||||
"tsconfigRootDir": ".",
|
||||
"ecmaVersion": 2022,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"accessor-pairs": "error",
|
||||
"block-spacing": ["error", "never"],
|
||||
"brace-style": ["error", "stroustrup", {"allowSingleLine": true}],
|
||||
"curly": ["error", "multi-line", "consistent"],
|
||||
"dot-location": ["error", "property"],
|
||||
"dot-notation": "error",
|
||||
"func-call-spacing": "error",
|
||||
"handle-callback-err": "error",
|
||||
"key-spacing": "error",
|
||||
"keyword-spacing": "error",
|
||||
"new-cap": ["error", {"newIsCap": true}],
|
||||
"no-array-constructor": "error",
|
||||
"no-caller": "error",
|
||||
"no-console": "error",
|
||||
"no-duplicate-imports": "error",
|
||||
"no-else-return": "error",
|
||||
"no-eval": "error",
|
||||
"no-floating-decimal": "error",
|
||||
"no-implied-eval": "error",
|
||||
"no-iterator": "error",
|
||||
"no-label-var": "error",
|
||||
"no-labels": "error",
|
||||
"no-lone-blocks": "error",
|
||||
"no-mixed-spaces-and-tabs": "error",
|
||||
"no-multi-spaces": "error",
|
||||
"no-multi-str": "error",
|
||||
"no-new": "error",
|
||||
"no-new-func": "error",
|
||||
"no-new-object": "error",
|
||||
"no-new-wrappers": "error",
|
||||
"no-octal-escape": "error",
|
||||
"no-path-concat": "error",
|
||||
"no-proto": "error",
|
||||
"no-prototype-builtins": "off",
|
||||
"no-redeclare": ["error", {"builtinGlobals": true}],
|
||||
"no-self-compare": "error",
|
||||
"no-sequences": "error",
|
||||
"no-shadow": ["warn", {"builtinGlobals": false, "hoist": "functions"}],
|
||||
"no-tabs": "error",
|
||||
"no-template-curly-in-string": "error",
|
||||
"no-throw-literal": "error",
|
||||
"no-undef": "error",
|
||||
"no-undef-init": "error",
|
||||
"no-unmodified-loop-condition": "error",
|
||||
"no-unneeded-ternary": "error",
|
||||
"no-useless-call": "error",
|
||||
"no-useless-computed-key": "error",
|
||||
"no-useless-constructor": "error",
|
||||
"no-useless-rename": "error",
|
||||
"no-var": "error",
|
||||
"no-whitespace-before-property": "error",
|
||||
"object-curly-spacing": ["error", "never", {"objectsInObjects": false}],
|
||||
"object-property-newline": ["error", {"allowAllPropertiesOnSameLine": true}],
|
||||
"operator-linebreak": ["error", "none", {"overrides": {"?": "before", ":": "before", "&&": "before"}}],
|
||||
"prefer-const": "error",
|
||||
"quote-props": ["error", "consistent-as-needed", {"keywords": true}],
|
||||
"quotes": ["error", "double", {"allowTemplateLiterals": true}],
|
||||
"rest-spread-spacing": "error",
|
||||
"semi": "error",
|
||||
"semi-spacing": "error",
|
||||
"space-before-blocks": "error",
|
||||
"space-in-parens": "error",
|
||||
"space-infix-ops": "error",
|
||||
"space-unary-ops": ["error", {"words": true, "nonwords": false, "overrides": {"typeof": false}}],
|
||||
"spaced-comment": ["error", "always", {"exceptions": ["-", "*"]}],
|
||||
"template-curly-spacing": "error",
|
||||
"wrap-iife": ["error", "inside"],
|
||||
"yield-star-spacing": "error",
|
||||
"yoda": "error"
|
||||
},
|
||||
"globals": {
|
||||
"NodeJS": "readonly"
|
||||
}
|
||||
}
|
4
packages/share-theme/.gitignore
vendored
Normal file
4
packages/share-theme/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
legacy/
|
||||
dist/
|
||||
.env
|
201
packages/share-theme/LICENSE
Normal file
201
packages/share-theme/LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
21
packages/share-theme/README.md
Normal file
21
packages/share-theme/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# [Trilium Rocks!](https://trilium.rocks/) [](https://discord.gg/eTaTXUgcBr)
|
||||
|
||||
[Trilium Notes](https://github.com/zadam/trilium) really does rock! Don't believe me? Well I created the entire [trilium.rocks](https://trilium.rocks) website using the shared notes feature inside Trilium with a little bit of extra CSS and JS also contained in Trilium. That JS and CSS? That's what you'll find here in this repository.
|
||||
|
||||
**Disclaimer:** This project and website is not at all affiliated with Trilium Notes or its creator(s).
|
||||
|
||||
## Why?
|
||||
|
||||
I love Trilium, it has made me the most organized I have ever been in my many many years of digital storage. The only thing I found lacking was the centralization of information. The [wiki](https://github.com/zadam/trilium/wiki) is a great resource, but it's outdated in some areas, and lacking in many many others—especially in regards to developing addons for Trilium. I also don't personally use gitter so the [official Trilium gitter](https://gitter.im/trilium-notes/Lobby) is not useful for me, and last time I checked it was _very_ inactive. So I made the website [trilium.rocks](https://trilium.rocks) and [a Discord server](https://discord.gg/eTaTXUgcBr) to try and help with each of those respectively.
|
||||
|
||||
With the website, I want to at least provide supplementary knowledge to the wiki by adding extended guides for users and developers. I also want to try and make it a more user-friendly central place to browse addons.
|
||||
|
||||
With the Discord server, I wanted to interact with the community and see what kind of addons people may be interested in. It also provides a quick and easy way to provide support to people, or even get support from others. And hopefully, it lets the community's developers come together to share information and make all of our addons even better.
|
||||
|
||||
## About The Site
|
||||
|
||||
Rather than saying some specific goals of what this site strives to be, I'll say what it strives not to be. This site is not meant to be a complete recreation of the Wiki with every detail and page included. It is meant to be a (mostly) one-stop shop for users and developers alike looking to supplement their knowledge. It may at some point expand and include everything from the wiki because users tend to prefer a fancier UI like this, but it is not the end-goal. It also may move in that direction if [zadam](https://github.com/zadam) wants to use this (or parts of this) project as part of the in-app documentation.
|
||||
|
||||
## Contributing
|
||||
|
||||
Since the entire site is just a share from my personal Trilium instance, there is no easy way to contribute new pages or fixes for typos. For now, this GitHub repo's issues and discussion can be used as places to contribute bug reports, feature requests, and even documentation contributions. But who knows, maybe soon I'll think of some clever way to introduce contributions directly to my Trilium instance.
|
29
packages/share-theme/TODO.md
Normal file
29
packages/share-theme/TODO.md
Normal file
@ -0,0 +1,29 @@
|
||||
# TODOs
|
||||
|
||||
This doc contains a list of TODOs taken from the code and organized. This _does not_ includes things like upcoming features or fixes.
|
||||
|
||||
## Scripts
|
||||
|
||||
- Create a logger
|
||||
- Modify esbuild to allow for a development build to contain debug logs
|
||||
- Modify custom highlight.js plugin to include highlighting for jQuery global functions
|
||||
- Either move highlight.js inclusion to template or use a mapping of note IDs to files
|
||||
- Adjust search to use separate function (clean code)
|
||||
- Consider never removing the search results from the page and update container instead
|
||||
- Consolidate theme initialization (DRY)
|
||||
|
||||
## Styles
|
||||
|
||||
-
|
||||
|
||||
## Templates
|
||||
|
||||
- Consider adding highlight.js into the templates instead of scripts
|
||||
- Find a better way to integrate ts/js to templates (maybe via includes?)
|
||||
|
||||
## Other
|
||||
|
||||
- Create a logical set of attributes for setting open-graph/twitter metadata
|
||||
- Consider making book type notes explicitly required for full-link category
|
||||
- This lets text type notes still have content but require clicking arrow to expand
|
||||
- Find a way to better map template to notes and allow for automatically creating new ones
|
2523
packages/share-theme/package-lock.json
generated
Normal file
2523
packages/share-theme/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
packages/share-theme/package.json
Normal file
29
packages/share-theme/package.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "trilium.rocks",
|
||||
"version": "1.0.3",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "esrun scripts/build.ts",
|
||||
"build-all": "esrun scripts/build.ts -- --templates",
|
||||
"build-scripts": "esrun scripts/build.ts -- --module=scripts",
|
||||
"build-styles": "esrun scripts/build.ts -- --module=styles",
|
||||
"templates": "esrun scripts/build.ts -- --only-templates",
|
||||
"dist": "esrun scripts/build.ts -- --minify",
|
||||
"test": "esrun src/scripts/test.ts"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@digitak/esrun": "^3.2.24",
|
||||
"@types/swagger-ui": "^3.52.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
||||
"@typescript-eslint/parser": "^6.7.2",
|
||||
"dotenv": "^16.3.1",
|
||||
"esbuild": "^0.19.3",
|
||||
"eslint": "^8.49.0",
|
||||
"highlight.js": "^11.8.0",
|
||||
"trilium-etapi": "^0.1.2",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
9
packages/share-theme/scripts/.eslintrc
Normal file
9
packages/share-theme/scripts/.eslintrc
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../.eslintrc",
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
"no-console": "off"
|
||||
}
|
||||
}
|
116
packages/share-theme/scripts/build.ts
Normal file
116
packages/share-theme/scripts/build.ts
Normal file
@ -0,0 +1,116 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
// import {fileURLToPath} from "node:url";
|
||||
|
||||
import dotenv from "dotenv";
|
||||
import tepi from "trilium-etapi";
|
||||
import * as esbuild from "esbuild";
|
||||
|
||||
|
||||
// const fileURL = fileURLToPath(import.meta.url);
|
||||
// let baseDir = path.dirname(fileURL);
|
||||
// if (fileURL.includes("esrun-")) baseDir = path.join(baseDir, "..", "..", "scripts");
|
||||
// const rootDir = path.join(baseDir, "..");
|
||||
// console.log(process.env.npm_package_json);
|
||||
const rootDir = path.dirname(process.env.npm_package_json!);
|
||||
|
||||
|
||||
dotenv.config();
|
||||
if (process.env.TRILIUM_ETAPI_TOKEN) tepi.token(process.env.TRILIUM_ETAPI_TOKEN);
|
||||
|
||||
|
||||
const templateMap: Record<string, string> = {
|
||||
page: process.env.PAGE_TEMPLATE_ID!,
|
||||
tree_item: process.env.ITEM_TEMPLATE_ID!,
|
||||
toc_item: process.env.TOC_TEMPLATE_ID!,
|
||||
};
|
||||
|
||||
async function sendTemplates() {
|
||||
for (const template in templateMap) {
|
||||
const templatePath = path.join(rootDir, "src", "templates", `${template}.ejs`);
|
||||
const contents = fs.readFileSync(templatePath).toString();
|
||||
await tepi.putNoteContentById(templateMap[template], contents);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv.includes("--only-templates")) {
|
||||
await sendTemplates();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const bundleMap = {
|
||||
"scripts.js": process.env.JS_NOTE_ID,
|
||||
"styles.css": process.env.CSS_NOTE_ID
|
||||
};
|
||||
|
||||
const triliumPlugin: esbuild.Plugin = {
|
||||
name: "Trilium",
|
||||
setup(build) {
|
||||
build.onEnd(async result => {
|
||||
if (!result.metafile) return;
|
||||
|
||||
const bundles = Object.keys(result.metafile.outputs);
|
||||
for (const bundle of bundles) {
|
||||
const filename = path.basename(bundle);
|
||||
const noteId = bundleMap[filename as keyof typeof bundleMap];
|
||||
if (!noteId) {
|
||||
console.info(`No note id found for bundle ${bundle}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const bundlePath = path.join(rootDir, bundle);
|
||||
if (!fs.existsSync(bundlePath)) {
|
||||
console.error(`Could not find bundle ${bundle}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const contents = fs.readFileSync(bundlePath).toString();
|
||||
await tepi.putNoteContentById(noteId, contents);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const modules = ["scripts", "styles"];
|
||||
const entryPoints: {in: string, out: string}[] = [];
|
||||
const makeEntry = (mod: string) => ({"in": path.join(rootDir, "src", mod, mod === "styles" ? "index.css" : "index.ts"), "out": mod});
|
||||
|
||||
const modulesRequested = process.argv.filter(a => a.startsWith("--module="));
|
||||
for (const mod of modulesRequested) {
|
||||
const module = mod?.replace("--module=", "") ?? "";
|
||||
if (modules.includes(module)) entryPoints.push(makeEntry(module));
|
||||
}
|
||||
|
||||
if (!entryPoints.length) for (const mod of modules) entryPoints.push(makeEntry(mod));
|
||||
|
||||
|
||||
async function runBuild() {
|
||||
const before = performance.now();
|
||||
await esbuild.build({
|
||||
entryPoints: entryPoints,
|
||||
bundle: true,
|
||||
outdir: path.join(rootDir, "dist"),
|
||||
format: "cjs",
|
||||
target: ["chrome96"],
|
||||
loader: {
|
||||
".png": "dataurl",
|
||||
".gif": "dataurl",
|
||||
".woff": "dataurl",
|
||||
".woff2": "dataurl",
|
||||
".ttf": "dataurl",
|
||||
".html": "text",
|
||||
".css": "css"
|
||||
},
|
||||
plugins: [triliumPlugin],
|
||||
logLevel: "info",
|
||||
metafile: true,
|
||||
minify: process.argv.includes("--minify")
|
||||
});
|
||||
const after = performance.now();
|
||||
if (process.argv.includes("--templates")) await sendTemplates();
|
||||
console.log(`Build actually took ${(after - before).toFixed(2)}ms`);
|
||||
}
|
||||
|
||||
runBuild().catch(console.error);
|
11
packages/share-theme/src/scripts/common/debounce.ts
Normal file
11
packages/share-theme/src/scripts/common/debounce.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export default function debounce<T extends (...args: unknown[]) => unknown>(executor: T, delay: number) {
|
||||
let timeout: NodeJS.Timeout | null;
|
||||
return function(...args: Parameters<T>): void {
|
||||
const callback = () => {
|
||||
timeout = null;
|
||||
Reflect.apply(executor, null, args);
|
||||
};
|
||||
if (timeout) clearTimeout(timeout);
|
||||
timeout = setTimeout(callback, delay);
|
||||
};
|
||||
}
|
7
packages/share-theme/src/scripts/common/parents.ts
Normal file
7
packages/share-theme/src/scripts/common/parents.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export default function parents<T extends HTMLElement>(el: T, selector: string) {
|
||||
const result = [];
|
||||
for (let p = el && el.parentElement; p; p = p.parentElement) {
|
||||
if (p.matches(selector)) result.push(p);
|
||||
}
|
||||
return result;
|
||||
}
|
7
packages/share-theme/src/scripts/common/parsehtml.ts
Normal file
7
packages/share-theme/src/scripts/common/parsehtml.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export default function parseHTML(html: string, fragment = false) {
|
||||
const template = document.createElement("template");
|
||||
template.innerHTML = html;
|
||||
const node = template.content.cloneNode(true);
|
||||
if (fragment) return node;
|
||||
return node.childNodes.length > 1 ? node.childNodes : node.childNodes[0];
|
||||
}
|
23
packages/share-theme/src/scripts/index.ts
Normal file
23
packages/share-theme/src/scripts/index.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import highlight from "./modules/highlight";
|
||||
import setupToC from "./modules/toc";
|
||||
import setupExpanders from "./modules/expanders";
|
||||
import setupMobileMenu from "./modules/mobile";
|
||||
import setupSearch from "./modules/search";
|
||||
import setupThemeSelector from "./modules/theme";
|
||||
|
||||
|
||||
function $try<T extends (...a: unknown[]) => unknown>(func: T, ...args: Parameters<T>) {
|
||||
try {
|
||||
func.apply(func, args);
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e); // eslint-disable-line no-console
|
||||
}
|
||||
}
|
||||
|
||||
$try(setupThemeSelector);
|
||||
$try(setupToC);
|
||||
$try(highlight);
|
||||
$try(setupExpanders);
|
||||
$try(setupMobileMenu);
|
||||
$try(setupSearch);
|
27
packages/share-theme/src/scripts/modules/expanders.ts
Normal file
27
packages/share-theme/src/scripts/modules/expanders.ts
Normal file
@ -0,0 +1,27 @@
|
||||
// In case a linked article lead to a new tree
|
||||
// const activeLink = document.querySelector("#menu a.active");
|
||||
// if (activeLink) {
|
||||
// let parent = activeLink.parentElement;
|
||||
// const mainMenu = document.getElementById("#menu");
|
||||
// while (parent && parent !== mainMenu) {
|
||||
// if (parent.matches(".submenu-item") && !parent.classList.contains("expanded")) {
|
||||
// parent.classList.add("expanded");
|
||||
// }
|
||||
// parent = parent.parentElement;
|
||||
// }
|
||||
// }
|
||||
|
||||
export default function setupExpanders() {
|
||||
const expanders = Array.from(document.querySelectorAll("#menu .submenu-item"));
|
||||
for (const ex of expanders) {
|
||||
ex.addEventListener("click", e => {
|
||||
if ((e.target as Element).closest(".submenu-item,.item") !== ex) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const ul = ex.querySelector("ul")!;
|
||||
ul.style.height = `${ul.scrollHeight}px`;
|
||||
setTimeout(() => ex.classList.toggle("expanded"), 1);
|
||||
setTimeout(() => ul.style.height = ``, 200);
|
||||
});
|
||||
}
|
||||
}
|
66
packages/share-theme/src/scripts/modules/highlight.ts
Normal file
66
packages/share-theme/src/scripts/modules/highlight.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import {HLJSApi, HLJSPlugin} from "highlight.js";
|
||||
|
||||
|
||||
declare const hljs: HLJSApi;
|
||||
|
||||
|
||||
// Custom highlight.js plugin to highlight the `api` globals for Trilium
|
||||
const highlightTriliumApi: HLJSPlugin = {
|
||||
"after:highlight": (result) => {
|
||||
result.value = result.value.replaceAll(/([^A-Za-z0-9])api\./g, function(match, prefix) {
|
||||
return `${prefix}<span class="hljs-variable language_">api</span>.`;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Custom highlight.js plugin to highlight JQuery function usage
|
||||
const highlightJQuery: HLJSPlugin = {
|
||||
"after:highlight": (result) => {
|
||||
result.value = result.value.replaceAll(/([^A-Za-z0-9.])\$\((.+)\)/g, function(match, prefix, variable) {
|
||||
return `${prefix}<span class="hljs-variable language_">$(</span>${variable}<span class="hljs-variable language_">)</span>`;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Let's highlight some codeblocks!
|
||||
*/
|
||||
export default function addHljs() {
|
||||
const codeblocks = document.querySelectorAll(`.ck-content pre`);
|
||||
if (!codeblocks.length) return; // If there are none, don't add dependency
|
||||
|
||||
// Add the hightlight.js styles from the child note of this script
|
||||
const link = document.createElement("link");
|
||||
link.rel = "stylesheet";
|
||||
link.href = "api/notes/cVaK9ZJwx5Hs/download";
|
||||
document.head.append(link);
|
||||
|
||||
// Add the highlight.js script too
|
||||
const script = document.createElement("script");
|
||||
script.src = "api/notes/6PVElIem02b5/download";
|
||||
script.addEventListener("load", () => {
|
||||
// hljs.configure({languageDetectRe: /\blanguage-text-x-([\w-]+)\b/i});
|
||||
|
||||
const allLanguages = hljs.listLanguages().map(l => {
|
||||
const definition = hljs.getLanguage(l);
|
||||
if (definition?.aliases) return [l, ...definition.aliases];
|
||||
return [l];
|
||||
});
|
||||
for (const langs of allLanguages) {
|
||||
const lang = langs[0];
|
||||
for (const l of langs) {
|
||||
hljs.registerAliases(`text-x-${l}`, {languageName: lang});
|
||||
}
|
||||
}
|
||||
|
||||
// This registers the JS Frontend and JS Backend types as javascript aliases for highlighting purposes
|
||||
hljs.registerAliases(["application-javascript-env-frontend", "application-javascript-env-backend"], {languageName: "javascript"});
|
||||
|
||||
// Add our custom plugins and highlight all on page
|
||||
hljs.addPlugin(highlightTriliumApi);
|
||||
hljs.addPlugin(highlightJQuery);
|
||||
hljs.highlightAll();
|
||||
});
|
||||
document.head.append(script);
|
||||
}
|
25
packages/share-theme/src/scripts/modules/mobile.ts
Normal file
25
packages/share-theme/src/scripts/modules/mobile.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import parents from "../common/parents";
|
||||
|
||||
|
||||
export default function setupMobileMenu() {
|
||||
function toggleMobileMenu(event: MouseEvent) {
|
||||
event.stopPropagation(); // Don't prevent default for links
|
||||
|
||||
const isOpen = document.body.classList.contains("menu-open");
|
||||
if (isOpen) return document.body.classList.remove("menu-open");
|
||||
return document.body.classList.add("menu-open");
|
||||
}
|
||||
|
||||
const showMenuButton = document.getElementById("show-menu-button");
|
||||
showMenuButton?.addEventListener("click", toggleMobileMenu);
|
||||
|
||||
window.addEventListener("click", e => {
|
||||
const isOpen = document.body.classList.contains("menu-open");
|
||||
if (!isOpen) return; // This listener is only to close
|
||||
|
||||
// If the click was anywhere in the mobile nav, don't close
|
||||
if (parents(e.target as HTMLElement, "#left-pane").length) return;
|
||||
return toggleMobileMenu(e);
|
||||
});
|
||||
|
||||
}
|
61
packages/share-theme/src/scripts/modules/search.ts
Normal file
61
packages/share-theme/src/scripts/modules/search.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import debounce from "../common/debounce";
|
||||
import parents from "../common/parents";
|
||||
import parseHTML from "../common/parsehtml";
|
||||
|
||||
|
||||
interface SearchResults {
|
||||
results: SearchResult[];
|
||||
}
|
||||
|
||||
interface SearchResult {
|
||||
id: string;
|
||||
title: string;
|
||||
score: number;
|
||||
path: string;
|
||||
}
|
||||
|
||||
function buildResultItem(result: SearchResult) {
|
||||
return `<a class="search-result-item" href="./${result.id}">
|
||||
<div class="search-result-title">${result.title}</div>
|
||||
<div class="search-result-note">${result.path || "Home"}</div>
|
||||
</a>`;
|
||||
}
|
||||
|
||||
|
||||
export default function setupSearch() {
|
||||
const searchInput: HTMLInputElement = document.querySelector(".search-input")!;
|
||||
|
||||
searchInput.addEventListener("keyup", debounce(async () => {
|
||||
// console.log("CHANGE EVENT");
|
||||
const ancestor = document.body.dataset.ancestorNoteId;
|
||||
const query = searchInput.value;
|
||||
if (query.length < 3) return;
|
||||
const resp = await fetch(`api/notes?search=${query}&ancestorNoteId=${ancestor}`);
|
||||
const json = await resp.json() as SearchResults;
|
||||
const results = json.results.slice(0, 5);
|
||||
const lines = [`<div class="search-results">`];
|
||||
for (const result of results) {
|
||||
lines.push(buildResultItem(result));
|
||||
}
|
||||
lines.push("</div>");
|
||||
|
||||
const container = parseHTML(lines.join("")) as HTMLDivElement;
|
||||
// console.log(container, lines);
|
||||
const rect = searchInput.getBoundingClientRect();
|
||||
container.style.top = `${rect.bottom}px`;
|
||||
container.style.left = `${rect.left}px`;
|
||||
container.style.minWidth = `${rect.width}px`;
|
||||
|
||||
const existing = document.querySelector(".search-results");
|
||||
if (existing) existing.replaceWith(container);
|
||||
else document.body.append(container);
|
||||
}, 500));
|
||||
|
||||
window.addEventListener("click", e => {
|
||||
const existing = document.querySelector(".search-results");
|
||||
if (!existing) return;
|
||||
// If the click was anywhere search components ignore it
|
||||
if (parents(e.target as HTMLElement, ".search-results,.search-item").length) return;
|
||||
if (existing) existing.remove();
|
||||
});
|
||||
}
|
35
packages/share-theme/src/scripts/modules/theme.ts
Normal file
35
packages/share-theme/src/scripts/modules/theme.ts
Normal file
@ -0,0 +1,35 @@
|
||||
const preference = localStorage.getItem("theme");
|
||||
if (preference) {
|
||||
if (preference === "dark") {
|
||||
document.body.classList.add("theme-dark");
|
||||
document.body.classList.remove("theme-light");
|
||||
}
|
||||
else {
|
||||
document.body.classList.remove("theme-dark");
|
||||
document.body.classList.add("theme-light");
|
||||
}
|
||||
}
|
||||
|
||||
export default function setupThemeSelector() {
|
||||
const themeSwitch: HTMLInputElement = document.querySelector(".theme-selection input")!;
|
||||
|
||||
if (preference) {
|
||||
const themeSelection: HTMLDivElement = document.querySelector(".theme-selection")!;
|
||||
themeSelection.classList.add("no-transition");
|
||||
themeSwitch.checked = preference === "dark";
|
||||
setTimeout(() => themeSelection.classList.remove("no-transition"), 400);
|
||||
}
|
||||
|
||||
themeSwitch?.addEventListener("change", () => {
|
||||
if (themeSwitch.checked) {
|
||||
document.body.classList.add("theme-dark");
|
||||
document.body.classList.remove("theme-light");
|
||||
localStorage.setItem("theme", "dark");
|
||||
}
|
||||
else {
|
||||
document.body.classList.remove("theme-dark");
|
||||
document.body.classList.add("theme-light");
|
||||
localStorage.setItem("theme", "light");
|
||||
}
|
||||
});
|
||||
}
|
46
packages/share-theme/src/scripts/modules/toc.ts
Normal file
46
packages/share-theme/src/scripts/modules/toc.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* The ToC is now generated in the page template so
|
||||
* it even exists for users without client-side js
|
||||
* and that means it loads with the page so it avoids
|
||||
* all potential reshuffling or layout recalculations.
|
||||
*
|
||||
* So, all this function needs to do is make the links
|
||||
* perform smooth animation, and adjust the "active"
|
||||
* entry as the user scrolls.
|
||||
*/
|
||||
export default function setupToC() {
|
||||
const toc = document.getElementById("toc");
|
||||
if (!toc) return;
|
||||
|
||||
// Get all relevant elements
|
||||
const sections = document.getElementById("content")!.querySelectorAll("h2, h3, h4, h5, h6");
|
||||
const links = toc.querySelectorAll("a");
|
||||
|
||||
// Setup smooth scroll on click
|
||||
for (const link of links) {
|
||||
link.addEventListener("click", e => {
|
||||
const target = document.querySelector(link.getAttribute("href")!);
|
||||
if (!target) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
target.scrollIntoView({behavior: "smooth"});
|
||||
});
|
||||
}
|
||||
|
||||
// Setup a moving "active" in the ToC that adjusts with the scroll state
|
||||
function changeLinkState() {
|
||||
let index = sections.length;
|
||||
|
||||
// Work backkwards to find the first matching section
|
||||
while (--index && window.scrollY + 50 < (sections[index] as HTMLElement).offsetTop) {} // eslint-disable-line no-empty
|
||||
|
||||
// Update the "active" item in ToC
|
||||
links.forEach((link) => link.classList.remove("active"));
|
||||
links[index].classList.add("active");
|
||||
}
|
||||
|
||||
// Initial render
|
||||
changeLinkState();
|
||||
window.addEventListener("scroll", changeLinkState);
|
||||
}
|
78
packages/share-theme/src/scripts/test.ts
Normal file
78
packages/share-theme/src/scripts/test.ts
Normal file
File diff suppressed because one or more lines are too long
56
packages/share-theme/src/styles/childlinks.css
Normal file
56
packages/share-theme/src/styles/childlinks.css
Normal file
@ -0,0 +1,56 @@
|
||||
#childLinks,
|
||||
#childLinks ul,
|
||||
#childLinks li {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#childLinks {
|
||||
padding-top: 10px;
|
||||
flex-direction: column;
|
||||
gap: 0px;
|
||||
justify-content: center;
|
||||
border-top: 1px solid var(--background-highlight);
|
||||
}
|
||||
|
||||
.no-content + #childLinks {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
#childLinks ul {
|
||||
padding: 0;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#childLinks li {
|
||||
padding: 0;
|
||||
background: var(--background-highlight);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
#childLinks li a {
|
||||
padding: 2px 12px;
|
||||
background: var(--background-highlight);
|
||||
border-radius: 12px;
|
||||
transform: translateY(0);
|
||||
transition: transform 200ms ease, background-color 200ms ease, color 200ms ease;
|
||||
}
|
||||
|
||||
#childLinks li a:hover {
|
||||
background: var(--background-active);
|
||||
color: var(--background-secondary);
|
||||
text-decoration: none;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
#childLinks.grid li a {
|
||||
padding: 50px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
#childLinks.grid li a:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
35
packages/share-theme/src/styles/content.css
Normal file
35
packages/share-theme/src/styles/content.css
Normal file
@ -0,0 +1,35 @@
|
||||
.ck-content code,
|
||||
.ck-content pre {
|
||||
color: var(--text-primary);
|
||||
background-color: var(--background-secondary);
|
||||
border: 1px solid var(--background-active);
|
||||
border-radius: 6px;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.ck-content code {
|
||||
padding: 2px 5px;
|
||||
}
|
||||
|
||||
.ck-content pre code {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.ck-content pre {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#content h1,
|
||||
#content h2,
|
||||
#content h3,
|
||||
#content h4,
|
||||
#content h5,
|
||||
#content h6 {
|
||||
color: var(--text-heading);
|
||||
border-bottom: 1px solid var(--background-highlight);
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
#content img {
|
||||
max-width: 100%;
|
||||
}
|
19
packages/share-theme/src/styles/externallinks.css
Normal file
19
packages/share-theme/src/styles/externallinks.css
Normal file
@ -0,0 +1,19 @@
|
||||
a[href^="https://"] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
#content a[href^="https://"] {
|
||||
padding-right: 6px;
|
||||
}
|
||||
|
||||
a[href^="https://"]::after {
|
||||
content: "";
|
||||
background-color: currentcolor;
|
||||
mask: url("data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"13.5\" height=\"13.5\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z\"></path></svg>");
|
||||
-webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"13.5\" height=\"13.5\" viewBox=\"0 0 24 24\"><path fill=\"currentColor\" d=\"M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z\"></path></svg>");
|
||||
width: 13.5px;
|
||||
height: 13.5px;
|
||||
display: inline-flex;
|
||||
}
|
80
packages/share-theme/src/styles/index.css
Normal file
80
packages/share-theme/src/styles/index.css
Normal file
@ -0,0 +1,80 @@
|
||||
@import "./childlinks.css";
|
||||
@import "./externallinks.css";
|
||||
@import "./swagger.css";
|
||||
@import "./toc.css";
|
||||
|
||||
@import "./navbar/index.css";
|
||||
@import "./popouts/index.css";
|
||||
|
||||
@import "./layout.css";
|
||||
@import "./content.css";
|
||||
|
||||
@import "./mobile.css";
|
||||
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/*
|
||||
Accent Color Ideas
|
||||
--text-link: #4693C3;
|
||||
--text-link: #F9B273;
|
||||
--text-link: #5CA9BF;
|
||||
--text-link: #E43F66;
|
||||
--text-link: #2FB8D1;
|
||||
--text-link: #A78BFA;
|
||||
--text-link: #F2B049;
|
||||
--text-link: #E47B19;
|
||||
--text-link: #FFB628;
|
||||
*/
|
||||
|
||||
:root {
|
||||
--background-primary: #333333;
|
||||
--background-secondary: #1F1F1F;
|
||||
--background-highlight: #484848;
|
||||
--background-active: #777777;
|
||||
--text-primary: #cccccc;
|
||||
--text-heading: #cccccc;
|
||||
--text-menu: #AAAAAA;
|
||||
--text-link: #87CEFA;
|
||||
--text-menu-active: #000000;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
body.theme-light {
|
||||
--background-primary: #FFFFFF;
|
||||
--background-secondary: #F3F3F3;
|
||||
--background-highlight: #DDDDDD;
|
||||
--background-active: #777777;
|
||||
--text-primary: #000000;
|
||||
--text-heading: #000000;
|
||||
--text-menu: #333333;
|
||||
--text-link: #0000ff;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background-primary);
|
||||
font-family: 'Montserrat', 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--text-link);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
pre, code, kbd, samp {
|
||||
font-family: "JetBrains Mono", Consolas, monospace;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
33
packages/share-theme/src/styles/layout.css
Normal file
33
packages/share-theme/src/styles/layout.css
Normal file
@ -0,0 +1,33 @@
|
||||
#split-pane {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 50px;
|
||||
}
|
||||
|
||||
#left-pane {
|
||||
display: flex;
|
||||
width: calc((100vw - 900px) / 2);
|
||||
min-width: fit-content;
|
||||
height: calc(100vh);
|
||||
background: var(--background-secondary);
|
||||
border-right: 5px solid var(--background-highlight);
|
||||
justify-content: flex-end;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#right-pane {
|
||||
display: flex;
|
||||
margin: 0 auto;
|
||||
gap: 40px;
|
||||
flex: 1;
|
||||
padding-bottom: 500px;
|
||||
padding-right: 50px;
|
||||
}
|
||||
|
||||
#main {
|
||||
order: 2;
|
||||
max-width: 900px;
|
||||
flex: 1;
|
||||
}
|
95
packages/share-theme/src/styles/mobile.css
Normal file
95
packages/share-theme/src/styles/mobile.css
Normal file
@ -0,0 +1,95 @@
|
||||
#mobile-header {
|
||||
display: none;
|
||||
background: var(--background-secondary);
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 6px 12px;
|
||||
}
|
||||
|
||||
#mobile-header a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
#mobile-header a img {
|
||||
max-width: 32px;
|
||||
}
|
||||
|
||||
#mobile-header button {
|
||||
color: var(--text-menu);
|
||||
background: transparent;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
border-radius: 6px;
|
||||
transform: rotate(0);
|
||||
transition: background-color 200ms ease, transform 200ms ease;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@media (max-width: 48em) {
|
||||
|
||||
#right-pane, #main {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#main {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
|
||||
#mobile-header {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#mobile-header button svg {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
#left-pane {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: auto;
|
||||
transform: translateX(-100%);
|
||||
transition: transform 200ms ease;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.menu-open #left-pane {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
body::before {
|
||||
content: "";
|
||||
display: block;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: rgba(0,0,0,0);
|
||||
pointer-events: none;
|
||||
transition: background-color 200ms ease;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
body.menu-open::before {
|
||||
background: rgba(0,0,0, 0.6);
|
||||
}
|
||||
|
||||
|
||||
body.menu-open #show-menu-button {
|
||||
background: var(--background-highlight);
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
}
|
149
packages/share-theme/src/styles/navbar/header.css
Normal file
149
packages/share-theme/src/styles/navbar/header.css
Normal file
@ -0,0 +1,149 @@
|
||||
#site-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
#site-header > a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
|
||||
/* The switch - the box around the slider */
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 60px;
|
||||
height: 27px; /* 32 */
|
||||
}
|
||||
|
||||
/* Hide default HTML checkbox */
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/* The slider */
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: var(--text-primary);;
|
||||
transition: 0.4s;
|
||||
border-radius: 34px;
|
||||
}
|
||||
|
||||
.slider::before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 19px; /* 26px */
|
||||
width: 19px;
|
||||
left: 4px;
|
||||
bottom: 4px;
|
||||
background-color: white;
|
||||
transition: 0.4s;
|
||||
border-radius: 50%;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: var(--background-highlight);
|
||||
}
|
||||
|
||||
input:focus + .slider {
|
||||
box-shadow: 0 0 1px var(--background-highlight);
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
transform: translateX(33px); /* whole width - slider width - 8px padding*/
|
||||
}
|
||||
|
||||
|
||||
.theme-selection {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.theme-selection.no-transition .slider,
|
||||
.theme-selection.no-transition .slider::before,
|
||||
.theme-selection.no-transition .dark-icon,
|
||||
.theme-selection.no-transition .light-icon {
|
||||
transition: none!important;
|
||||
}
|
||||
|
||||
|
||||
.theme-selection label {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.dark-icon, .light-icon {
|
||||
display: flex;
|
||||
opacity: 0;
|
||||
transition: opacity 400ms ease, color 400ms ease;
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
height: 100%;
|
||||
width: 24px;
|
||||
}
|
||||
|
||||
/* input ~ .dark-icon {
|
||||
display: none;
|
||||
} */
|
||||
|
||||
input:not(:checked) ~ .light-icon {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
input:checked ~ .dark-icon {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* input:checked ~ .light-icon {
|
||||
display: none;
|
||||
} */
|
||||
|
||||
|
||||
.dark-icon {
|
||||
left: 5px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.light-icon {
|
||||
right: 5px;
|
||||
color: var(--background-highlight);
|
||||
}
|
||||
|
||||
|
||||
.search-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
color: var(--text-primary);
|
||||
background: var(--background-highlight);
|
||||
outline: 0;
|
||||
border: 0;
|
||||
flex: 1;
|
||||
padding: 5px 5px 5px 32px;
|
||||
width: 200px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
display: flex;
|
||||
color: var(--text-primary);
|
||||
position: absolute;
|
||||
width: 20px;
|
||||
left: 5px;
|
||||
}
|
2
packages/share-theme/src/styles/navbar/index.css
Normal file
2
packages/share-theme/src/styles/navbar/index.css
Normal file
@ -0,0 +1,2 @@
|
||||
@import "./header.css";
|
||||
@import "./navbar.css";
|
148
packages/share-theme/src/styles/navbar/navbar.css
Normal file
148
packages/share-theme/src/styles/navbar/navbar.css
Normal file
@ -0,0 +1,148 @@
|
||||
#navigation {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 25px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
#menu {
|
||||
order: 1;
|
||||
/* margin-left: auto; */
|
||||
|
||||
white-space: nowrap;
|
||||
|
||||
flex: 0;
|
||||
/* padding: 25px; */
|
||||
}
|
||||
|
||||
#menu > ul {
|
||||
overflow-y: auto;
|
||||
list-style: none;
|
||||
padding-left: 0!important;
|
||||
}
|
||||
|
||||
/* #menu > ul, #menu > div {
|
||||
width: fit-content;
|
||||
margin-left: auto;
|
||||
} */
|
||||
|
||||
#menu ul {
|
||||
overflow-y: hidden;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
list-style: none;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
#menu li {
|
||||
/* overflow-y: hidden; */
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
list-style: none;
|
||||
cursor: pointer;
|
||||
max-width: 350px;
|
||||
}
|
||||
|
||||
#menu li span {
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
#menu li .collapsible-label {
|
||||
display: flex;
|
||||
flex: 1
|
||||
}
|
||||
|
||||
#menu li > ul {
|
||||
transition: height 200ms ease;
|
||||
}
|
||||
|
||||
#menu li:not(.expanded) > ul {
|
||||
height: 0!important;
|
||||
/* transition: height 1000ms ease; */
|
||||
}
|
||||
|
||||
#menu li.expanded > ul {
|
||||
/* max-height: 500px; */
|
||||
}
|
||||
|
||||
#menu p {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#menu li.item > a {
|
||||
padding-left: 24px;
|
||||
}
|
||||
|
||||
#menu a {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
gap: 5px;
|
||||
color: var(--text-menu);
|
||||
text-decoration: none;
|
||||
border-radius: 6px;
|
||||
border: 1px solid transparent;
|
||||
flex: 1;
|
||||
padding: 2px 6px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
#menu a:hover {
|
||||
border-color: var(--text-menu);
|
||||
}
|
||||
|
||||
#menu a.active {
|
||||
background: var(--background-active);
|
||||
color: var(--background-secondary);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
#menu li ul {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#menu li ul::before {
|
||||
content: "";
|
||||
display: flex;
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
bottom: 5px;
|
||||
left: 10px;
|
||||
width: 2px;
|
||||
background: var(--background-highlight);
|
||||
}
|
||||
|
||||
.active .collapse-button {
|
||||
background: none;
|
||||
color: var(--background-secondary);
|
||||
}
|
||||
|
||||
|
||||
.collapse-button {
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
background: var(--background-secondary);
|
||||
border: 0;
|
||||
color: var(--text-menu);
|
||||
/* position: absolute; */
|
||||
/* top: 2px; */
|
||||
/* left: -18px; */
|
||||
transform: rotate(-90deg);
|
||||
transition: transform 200ms ease;
|
||||
}
|
||||
|
||||
.expanded > .collapse-button,
|
||||
.expanded > a > .collapse-button {
|
||||
transform: rotate(0);
|
||||
}
|
||||
|
||||
.collapse-button svg {
|
||||
width: 14px;
|
||||
}
|
1
packages/share-theme/src/styles/popouts/index.css
Normal file
1
packages/share-theme/src/styles/popouts/index.css
Normal file
@ -0,0 +1 @@
|
||||
@import "./search.css";
|
34
packages/share-theme/src/styles/popouts/search.css
Normal file
34
packages/share-theme/src/styles/popouts/search.css
Normal file
@ -0,0 +1,34 @@
|
||||
.search-results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: fixed;
|
||||
background: var(--background-highlight);
|
||||
margin-top: 10px;
|
||||
border-radius: 12px;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
.search-result-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 4px 12px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.search-result-item:hover {
|
||||
cursor: pointer;
|
||||
background: var(--background-active);
|
||||
color: var(--text-menu-active);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.search-result-item:hover .search-result-note {
|
||||
color: var(--text-menu-active);
|
||||
}
|
||||
|
||||
.search-result-note {
|
||||
font-size: 12px;
|
||||
color: var(--text-menu);
|
||||
}
|
143
packages/share-theme/src/styles/swagger.css
Normal file
143
packages/share-theme/src/styles/swagger.css
Normal file
@ -0,0 +1,143 @@
|
||||
#main .swagger-ui .scheme-container {
|
||||
background: var(--background-secondary);
|
||||
}
|
||||
|
||||
#main .swagger-ui .opblock .opblock-section-header {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
#main .swagger-ui section.models {
|
||||
border: 1px solid var(--background-highlight);
|
||||
}
|
||||
|
||||
#main .swagger-ui section.models .model-container,
|
||||
#main .swagger-ui .opblock-body pre.microlight {
|
||||
background: var(--background-secondary) !important;
|
||||
}
|
||||
|
||||
#main .swagger-ui,
|
||||
#main .swagger-ui .info li,
|
||||
#main .swagger-ui .info p,
|
||||
#main .swagger-ui .info table,
|
||||
#main .swagger-ui .opblock-description-wrapper p,
|
||||
#main .swagger-ui .opblock-external-docs-wrapper p,
|
||||
#main .swagger-ui .opblock-title_normal p,
|
||||
#main .swagger-ui .response-col_status,
|
||||
#main .swagger-ui .response-col_links {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
|
||||
#main .swagger-ui .opblock .opblock-summary-operation-id,
|
||||
#main .swagger-ui .opblock .opblock-summary-path,
|
||||
#main .swagger-ui .opblock .opblock-summary-path__deprecated,
|
||||
#main .swagger-ui .btn,
|
||||
#main .swagger-ui .model,
|
||||
#main .swagger-ui .tab li,
|
||||
#main .swagger-ui table thead tr td,
|
||||
#main .swagger-ui table thead tr th,
|
||||
#main .swagger-ui .parameter__type,
|
||||
#main .swagger-ui .parameter__name,
|
||||
#main .swagger-ui thead tr td.col_header,
|
||||
#main .swagger-ui .model-title {
|
||||
color: var(--text-heading);
|
||||
}
|
||||
|
||||
#main .swagger-ui .model .property.primitive {
|
||||
color: var(--text-menu);
|
||||
}
|
||||
|
||||
#main .swagger-ui .prop-type {
|
||||
color: var(--text-link);
|
||||
}
|
||||
|
||||
#main .swagger-ui svg {
|
||||
fill: var(--text-heading);
|
||||
}
|
||||
|
||||
|
||||
#main .swagger-ui .model-toggle::after {
|
||||
filter: invert(100%);
|
||||
}
|
||||
|
||||
#main .swagger-ui .btn {
|
||||
border: 2px solid var(--text-heading);
|
||||
transition: transform 200ms ease;
|
||||
}
|
||||
|
||||
#main .swagger-ui .btn:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
#main .swagger-ui input[disabled],
|
||||
#main .swagger-ui select[disabled],
|
||||
#main .swagger-ui textarea[disabled],
|
||||
#main .swagger-ui select {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
color: var(--text-primary);
|
||||
border: 2px solid rgba(0,0,0,0.3);
|
||||
appearance: auto;
|
||||
}
|
||||
|
||||
|
||||
#main .models > h4 {
|
||||
margin: 5px 10px;
|
||||
}
|
||||
|
||||
|
||||
#main .swagger-ui .opblock-summary-control {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
#main .swagger-ui .authorization__btn {
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.swagger-ui .info .title small {
|
||||
top: 0;
|
||||
padding: 4px 8px;
|
||||
background: var(--background-highlight);
|
||||
}
|
||||
|
||||
#main .swagger-ui .info .title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
#main .swagger-ui .info .title small pre {
|
||||
color: var(--text-heading);
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
}
|
||||
|
||||
#main .swagger-ui .info .title > span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.swagger-ui .info .title small.version-stamp {
|
||||
background: var(--background-highlight);
|
||||
}
|
||||
|
||||
|
||||
#main .swagger-ui h1,
|
||||
#main .swagger-ui h2,
|
||||
#main .swagger-ui h3,
|
||||
#main .swagger-ui h4,
|
||||
#main .swagger-ui h5,
|
||||
#main .swagger-ui h6 {
|
||||
border: 0;
|
||||
}
|
||||
|
||||
|
||||
#main .swagger-ui input[type="email"],
|
||||
#main .swagger-ui input[type="file"],
|
||||
#main .swagger-ui input[type="password"],
|
||||
#main .swagger-ui input[type="search"],
|
||||
#main .swagger-ui input[type="text"],
|
||||
#main .swagger-ui textarea {
|
||||
background-color: var(--background-highlight);
|
||||
border: 0;
|
||||
}
|
94
packages/share-theme/src/styles/toc.css
Normal file
94
packages/share-theme/src/styles/toc.css
Normal file
@ -0,0 +1,94 @@
|
||||
#toc-pane {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: fit-content;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
order: 3;
|
||||
/* padding: 16px 16px 16px 32px; */
|
||||
}
|
||||
|
||||
#toc-pane h3 {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
#toc {
|
||||
position: relative;
|
||||
height: fit-content;
|
||||
margin: 0;
|
||||
border-radius: 6px;
|
||||
padding: 0 0 0 16px;
|
||||
max-width: 250px;
|
||||
}
|
||||
|
||||
#toc, #toc ul {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#toc ul {
|
||||
padding-left: 16px;
|
||||
}
|
||||
|
||||
#toc span {
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#toc li a {
|
||||
/* position: relative; */
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: var(--text-heading);
|
||||
transition: color 200ms ease;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#toc li a:hover,
|
||||
#toc li a.active {
|
||||
color: var(--text-link);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#toc li a::before {
|
||||
content: "";
|
||||
display: flex;
|
||||
position: absolute;
|
||||
width: 2px;
|
||||
height: 16px;
|
||||
background: transparent;
|
||||
left: 0;
|
||||
transition: background-color 200ms ease;
|
||||
}
|
||||
|
||||
#toc li a.active::before {
|
||||
background: var(--text-link);
|
||||
}
|
||||
|
||||
#toc::before {
|
||||
content: "";
|
||||
display: block;
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
top: 4px;
|
||||
width: 2px;
|
||||
height: calc(100% - 8px);
|
||||
background: var(--background-highlight);
|
||||
}
|
||||
|
||||
#content h1 a.toc-anchor,
|
||||
#content h2 a.toc-anchor,
|
||||
#content h3 a.toc-anchor,
|
||||
#content h4 a.toc-anchor,
|
||||
#content h5 a.toc-anchor,
|
||||
#content h6 a.toc-anchor {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
#toc-pane {
|
||||
display: none;
|
||||
}
|
||||
}
|
244
packages/share-theme/src/templates/page.ejs
Normal file
244
packages/share-theme/src/templates/page.ejs
Normal file
@ -0,0 +1,244 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link rel="shortcut icon" href="<% if (note.hasRelation("shareFavicon")) { %>api/notes/<%= note.getRelation("shareFavicon").value %>/download<% } else { %>../favicon.ico<% } %>">
|
||||
<script src="../<%= appPath %>/share.js"></script>
|
||||
<link href="../<%= assetPath %>/libraries/normalize.min.css" rel="stylesheet">
|
||||
|
||||
<% if (note.hasLabel("shareSwagger")) { %>
|
||||
<!-- TODO: make these note IDs customizable -->
|
||||
<link href="api/notes/woA8jsLWd4QR/download" rel="stylesheet">
|
||||
<script src="api/notes/RYOdL9flwQfP/download"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const customServerYml = `- url: "{protocol}://{domain}:{port}/etapi"
|
||||
variables:
|
||||
protocol:
|
||||
enum:
|
||||
- http
|
||||
- https
|
||||
default: http
|
||||
description: Protocol your server is being hosted with
|
||||
domain:
|
||||
default: localhost
|
||||
description: Domain name or localhost or ip
|
||||
port:
|
||||
default: 37840
|
||||
description: Port the app is served over`;
|
||||
|
||||
SwaggerUIBundle({
|
||||
// url: `api/notes/<%= note.noteId %>/download`,
|
||||
url: `<%= note.getLabelValue("shareSwagger") %>`,
|
||||
dom_id: "#content",
|
||||
responseInterceptor: resp => {
|
||||
if (resp.url !== `<%= note.getLabelValue("shareSwagger") %>`) return resp;
|
||||
resp.text = resp.text.replace("- url: http://localhost:37740/etapi", "- url: http://localhost:37840/etapi");
|
||||
resp.text = resp.text.replace(`- url: http://localhost:8080/etapi`, customServerYml);
|
||||
return resp;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<% } %>
|
||||
|
||||
<% if (note.type === "text" || note.type === "book") { %>
|
||||
<link href="../<%= assetPath %>/libraries/ckeditor/ckeditor-content.css" rel="stylesheet">
|
||||
<% } %>
|
||||
<% for (const cssRelation of note.getRelations("shareCss")) { %>
|
||||
<link href="api/notes/<%= cssRelation.value %>/download" rel="stylesheet">
|
||||
<% } %>
|
||||
<% for (const jsRelation of note.getRelations("shareJs")) { %>
|
||||
<script type="module" src="api/notes/<%= jsRelation.value %>/download"></script>
|
||||
<% } %>
|
||||
<% if (note.hasLabel("shareDisallowRobotIndexing")) { %>
|
||||
<meta name="robots" content="noindex,follow" />
|
||||
<% } %>
|
||||
|
||||
<%
|
||||
const pageTitle = `${note.title}${note.noteId !== subRoot.note.noteId ? ` - ${subRoot.note.title}` : ""}`;
|
||||
|
||||
// Setup some key OpenGraph variables
|
||||
const openGraphColor = subRoot.note.getLabelValue("shareOpenGraphColor");
|
||||
const openGraphURL = subRoot.note.getLabelValue("shareOpenGraphURL");
|
||||
const openGraphDomain = subRoot.note.getLabelValue("shareOpenGraphDomain");
|
||||
let openGraphImage = subRoot.note.getLabelValue("shareOpenGraphImage");
|
||||
// Relation takes priority and requires some altering
|
||||
if (subRoot.note.hasRelation("shareOpenGraphImage")) {
|
||||
openGraphImage = `api/images/${subRoot.note.getRelation("shareOpenGraphImage").value}/image.png`;
|
||||
}
|
||||
%>
|
||||
<title><%= pageTitle %></title>
|
||||
<!-- HTML Meta Tags -->
|
||||
<meta name="description" content="<%= note.getLabelValue("shareDescription") %>">
|
||||
<!-- Facebook Meta Tags -->
|
||||
<meta property="og:url" content="<%= openGraphURL %>">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:title" content="<%= pageTitle %>">
|
||||
<meta property="og:description" content="<%= note.getLabelValue("shareDescription") %>">
|
||||
<meta property="og:image" content="<%= openGraphImage %>">
|
||||
<!-- Twitter Meta Tags -->
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta property="twitter:domain" content="<%= openGraphDomain %>">
|
||||
<meta property="twitter:url" content="<%= openGraphURL %>">
|
||||
<meta name="twitter:title" content="<%= pageTitle %>">
|
||||
<meta name="twitter:description" content="<%= note.getLabelValue("shareDescription") %>">
|
||||
<meta name="twitter:image" content="<%= openGraphImage %>">
|
||||
<!-- Meta Tags Generated via https://opengraph.dev -->
|
||||
<meta name="theme-color" content="<%= openGraphColor %>">
|
||||
</head>
|
||||
<%
|
||||
const logoWidth = subRoot.note.getLabelValue("shareLogoWidth");
|
||||
const logoHeight = subRoot.note.getLabelValue("shareLogoHeight");
|
||||
const mobileLogoHeight = logoHeight && logoWidth ? 32 / (logoWidth / logoHeight) : "";
|
||||
const shareRootLink = subRoot.note.hasLabel("shareRootLink") ? subRoot.note.getLabelValue("shareRootLink") : `./${subRoot.note.noteId}`;
|
||||
const currentTheme = note.getLabel("shareTheme") === "light" ? "light" : "dark";
|
||||
const themeClass = currentTheme === "light" ? " theme-light" : " theme-dark";
|
||||
const headingRe = /(<h[1-6]>)(.+?)(<\/h[1-6]>)/g;
|
||||
const headingMatches = [...content.matchAll(headingRe)];
|
||||
const slugify = (text) => text.toLowerCase().replace(/[^\w]/g, "-");
|
||||
content = content.replaceAll(headingRe, (...match) => {
|
||||
match[0] = match[0].replace(match[3], `<a id="${slugify(match[2])}" class="toc-anchor" name="${slugify(match[2])}" href="#${slugify(match[2])}">#</a>${match[3]}`);
|
||||
return match[0];
|
||||
});
|
||||
%>
|
||||
<body data-note-id="<%= note.noteId %>" class="type-<%= note.type %><%= themeClass %>" data-ancestor-note-id="<%= subRoot.note.noteId %>">
|
||||
<script>
|
||||
const preference = localStorage.getItem("theme");
|
||||
if (preference) {
|
||||
if (preference === "dark") {
|
||||
document.body.classList.add("theme-dark");
|
||||
document.body.classList.remove("theme-light");
|
||||
}
|
||||
else {
|
||||
document.body.classList.remove("theme-dark");
|
||||
document.body.classList.add("theme-light");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<div id="mobile-header">
|
||||
<a href="<%= shareRootLink %>">
|
||||
<% if (subRoot.note.hasRelation("shareLogo")) { %>
|
||||
<img src="api/images/<%= subRoot.note.getRelation("shareLogo").value %>/image.png" width="32" height="<%= mobileLogoHeight %>" alt="Logo" />
|
||||
<% } %>
|
||||
<%= subRoot.note.title %>
|
||||
</a>
|
||||
<button aria-label="Show Mobile Menu" id="show-menu-button"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M4 6h16v2H4zm0 5h16v2H4zm0 5h16v2H4z"></path></svg></button>
|
||||
</div>
|
||||
<div id="split-pane">
|
||||
<div id="left-pane">
|
||||
<div id="navigation">
|
||||
<div id="site-header">
|
||||
<a href="<%= shareRootLink %>">
|
||||
<% if (subRoot.note.hasRelation("shareLogo")) { %>
|
||||
<img src="api/images/<%= subRoot.note.getRelation("shareLogo").value %>/image.png" width="<%= logoWidth %>" height="<%= logoHeight %>" alt="Logo" />
|
||||
<% } %>
|
||||
<%= subRoot.note.title %>
|
||||
</a>
|
||||
<div class="theme-selection">
|
||||
<span id="sitetheme">Site Theme</span>
|
||||
<label class="switch">
|
||||
<input type="checkbox" checked="<%= currentTheme === "dark" %>" aria-labelledby="sitetheme">
|
||||
<span class="slider"></span>
|
||||
<svg class="dark-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M20.742 13.045a8.088 8.088 0 0 1-2.077.271c-2.135 0-4.14-.83-5.646-2.336a8.025 8.025 0 0 1-2.064-7.723A1 1 0 0 0 9.73 2.034a10.014 10.014 0 0 0-4.489 2.582c-3.898 3.898-3.898 10.243 0 14.143a9.937 9.937 0 0 0 7.072 2.93 9.93 9.93 0 0 0 7.07-2.929 10.007 10.007 0 0 0 2.583-4.491 1.001 1.001 0 0 0-1.224-1.224zm-2.772 4.301a7.947 7.947 0 0 1-5.656 2.343 7.953 7.953 0 0 1-5.658-2.344c-3.118-3.119-3.118-8.195 0-11.314a7.923 7.923 0 0 1 2.06-1.483 10.027 10.027 0 0 0 2.89 7.848 9.972 9.972 0 0 0 7.848 2.891 8.036 8.036 0 0 1-1.484 2.059z"></path></svg>
|
||||
<svg class="light-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M6.993 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007S14.761 6.993 12 6.993 6.993 9.239 6.993 12zM12 8.993c1.658 0 3.007 1.349 3.007 3.007S13.658 15.007 12 15.007 8.993 13.658 8.993 12 10.342 8.993 12 8.993zM10.998 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2h-3zm17 0h3v2h-3zM4.219 18.363l2.12-2.122 1.415 1.414-2.12 2.122zM16.24 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.342 7.759 4.22 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path></svg>
|
||||
</label>
|
||||
</div>
|
||||
<div class="search-item">
|
||||
<svg class="search-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M10 18a7.952 7.952 0 0 0 4.897-1.688l4.396 4.396 1.414-1.414-4.396-4.396A7.952 7.952 0 0 0 18 10c0-4.411-3.589-8-8-8s-8 3.589-8 8 3.589 8 8 8zm0-14c3.309 0 6 2.691 6 6s-2.691 6-6 6-6-2.691-6-6 2.691-6 6-6z"></path></svg>
|
||||
<input type="text" class="search-input" placeholder="Search...">
|
||||
</div>
|
||||
</div>
|
||||
<% if (subRoot.note.hasVisibleChildren()) { %>
|
||||
<nav id="menu">
|
||||
<%
|
||||
const ancestors = [];
|
||||
let notePointer = note;
|
||||
while (notePointer.parents[0].noteId !== "_share") {
|
||||
const pointerParent = notePointer.parents[0];
|
||||
ancestors.push(pointerParent.noteId);
|
||||
notePointer = pointerParent;
|
||||
}
|
||||
%>
|
||||
<%- include("tree_item", {note: subRoot.note, activeNote: note, subRoot: subRoot, ancestors: ancestors}) %>
|
||||
</nav>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
<div id="right-pane">
|
||||
<div id="main">
|
||||
|
||||
<div id="content" class="type-<%= note.type %><% if (note.type === "text") { %> ck-content<% } %><% if (isEmpty) { %> no-content<% } %>">
|
||||
<h1 id="title"><%= note.title %></h1>
|
||||
<% if (isEmpty && (!note.hasVisibleChildren() && note.type !== "book")) { %>
|
||||
<p>This note has no content.</p>
|
||||
<% } else { %>
|
||||
<%
|
||||
content = content.replace(/<img /g, `<img alt="Article Image" loading="lazy" `);
|
||||
%>
|
||||
<%- content %>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<% if (note.hasVisibleChildren() || note.type === "book") { %>
|
||||
<nav id="childLinks" class="<% if (isEmpty) { %>grid<% } else { %>list<% } %>">
|
||||
<% if (!isEmpty) { %>
|
||||
<span>Subpages:</span>
|
||||
<% } %>
|
||||
|
||||
<ul>
|
||||
<%
|
||||
const action = note.type === "book" ? "getChildNotes" : "getVisibleChildNotes";
|
||||
for (const childNote of note[action]()) {
|
||||
const isExternalLink = childNote.hasLabel("shareExternal") || childNote.hasLabel("shareExternalLink");
|
||||
const linkHref = isExternalLink ? childNote.getLabelValue("shareExternal") ?? childNote.getLabelValue("shareExternalLink") : `./${childNote.shareId}`;
|
||||
const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : "";
|
||||
%>
|
||||
<li>
|
||||
<a class="type-<%= childNote.type %>" href="<%= linkHref %>"<%= target %>><%= childNote.title %></a>
|
||||
</li>
|
||||
<% } %>
|
||||
</ul>
|
||||
</nav>
|
||||
<% } %>
|
||||
</div>
|
||||
<%
|
||||
if (headingMatches.length > 1) {
|
||||
const level = (m) => parseInt(m[1].replace(/[<h>]+/g, ""));
|
||||
|
||||
const toc = [
|
||||
{
|
||||
level: level(headingMatches[0]),
|
||||
name: headingMatches[0][2],
|
||||
children: []
|
||||
}
|
||||
];
|
||||
const last = (arr = toc) => arr[arr.length - 1];
|
||||
const makeEntry = (m) => ({level: level(m), name: m[2], children: []});
|
||||
const getLevelArr = (lvl, arr = toc) => {
|
||||
if (arr[0].level === lvl) return arr;
|
||||
const top = last(arr);
|
||||
return top.children.length ? getLevelArr(lvl, top.children) : top.children;
|
||||
};
|
||||
|
||||
|
||||
for (let m = 1; m < headingMatches.length; m++) {
|
||||
const target = getLevelArr(level(headingMatches[m]));
|
||||
target.push(makeEntry(headingMatches[m]));
|
||||
}
|
||||
%>
|
||||
<div id="toc-pane">
|
||||
<h3>On This Page</h3>
|
||||
<ul id="toc">
|
||||
<% for (const entry of toc) { %>
|
||||
<%- include("toc_item", {entry}) %>
|
||||
<% } %>
|
||||
</ul>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
19
packages/share-theme/src/templates/toc_item.ejs
Normal file
19
packages/share-theme/src/templates/toc_item.ejs
Normal file
@ -0,0 +1,19 @@
|
||||
<%
|
||||
const slugify = (text) => text.toLowerCase().replace(/[^\w]/g, "-");
|
||||
const slug = slugify(entry.name);
|
||||
%>
|
||||
|
||||
|
||||
<li>
|
||||
<a href="#<%= slug %>">
|
||||
<span><%= entry.name %></span>
|
||||
</a>
|
||||
|
||||
<% if (entry.children.length) { %>
|
||||
<ul>
|
||||
<% for (const subentry of entry.children) { %>
|
||||
<%- include('toc_item', {entry: subentry}) %>
|
||||
<% } %>
|
||||
</ul>
|
||||
<% } %>
|
||||
</li>
|
29
packages/share-theme/src/templates/tree_item.ejs
Normal file
29
packages/share-theme/src/templates/tree_item.ejs
Normal file
@ -0,0 +1,29 @@
|
||||
<%
|
||||
const linkClass = `type-${note.type}` + (activeNote.noteId === note.noteId ? " active" : "");
|
||||
const isExternalLink = note.hasLabel("shareExternal");
|
||||
const linkHref = isExternalLink ? note.getLabelValue("shareExternal") : `./${note.shareId}`;
|
||||
const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : "";
|
||||
%>
|
||||
|
||||
<% if (note.noteId !== subRoot.note.noteId) { %>
|
||||
<a class="<%= linkClass %>" href="<%= linkHref %>"<%= target %>>
|
||||
<% if (note.hasVisibleChildren()) { %><button class="collapse-button" aria-label="Expand"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon right-triangle"><path d="M3 8L12 17L21 8"></path></svg></button><% } %>
|
||||
<span><%= note.title %></span>
|
||||
</a>
|
||||
<% } %>
|
||||
|
||||
|
||||
<% if (note.hasVisibleChildren()) { %>
|
||||
<ul>
|
||||
<% note.getVisibleChildNotes().forEach(function (childNote) { %>
|
||||
<%
|
||||
const hasChildren = childNote.hasVisibleChildren();
|
||||
const isAncestorOfActive = ancestors.some(p => p === childNote.noteId);
|
||||
const expandedClass = isAncestorOfActive ? " expanded" : "";
|
||||
%>
|
||||
<li class="<% if (hasChildren) { %>submenu-<% } %>item<%= expandedClass %>">
|
||||
<%- include('tree_item', {note: childNote, subRoot: subRoot}) %>
|
||||
</li>
|
||||
<% }) %>
|
||||
</ul>
|
||||
<% } %>
|
8
packages/share-theme/tsconfig.eslint.json
Normal file
8
packages/share-theme/tsconfig.eslint.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src/**/*", "scripts/*"],
|
||||
}
|
16
packages/share-theme/tsconfig.json
Normal file
16
packages/share-theme/tsconfig.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"resolveJsonModule": true,
|
||||
"strictNullChecks": true,
|
||||
"moduleResolution": "Node16",
|
||||
"target": "ES2022",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib/cjs",
|
||||
"module": "Node16"
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user