From e78f01f79d351817d2228ae2a98dd4e46d26210a Mon Sep 17 00:00:00 2001 From: mnerv Date: Sat, 4 Nov 2023 01:33:59 +0100 Subject: [PATCH] Show children count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Linjär Algebra --- .../1a-normalform_planet_tre_punkter.tex" | 0 package.json | 3 ++- src/App.svelte | 3 ++- src/FileTree.ts | 15 ++++++++++++++- src/main.ts | 10 +++++++++- src/vite-env.d.ts | 11 +++++++++++ vite.config.ts | 14 ++++++++++++++ 7 files changed, 52 insertions(+), 4 deletions(-) rename "linj\303\244r_algebra/20220114/1a.tex" => "linj\303\244r_algebra/20220114/1a-normalform_planet_tre_punkter.tex" (100%) diff --git "a/linj\303\244r_algebra/20220114/1a.tex" "b/linj\303\244r_algebra/20220114/1a-normalform_planet_tre_punkter.tex" similarity index 100% rename from "linj\303\244r_algebra/20220114/1a.tex" rename to "linj\303\244r_algebra/20220114/1a-normalform_planet_tre_punkter.tex" diff --git a/package.json b/package.json index c80fe81..f243755 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "maths", "private": true, - "version": "0.0.1", + "version": "0.0.2", + "homepage": "https://github.com/mnerv/maths", "repository": { "type": "github", "url": "https://github.com/mnerv/maths" diff --git a/src/App.svelte b/src/App.svelte index bb62746..3dc7708 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -2,7 +2,7 @@ import { onMount } from 'svelte' import File from './File.svelte'; import FileTree from './FileTree.svelte'; - import { pathsToFileTree, type NodeT } from './FileTree'; + import { pathsToFileTree, type NodeT, sortByType } from './FileTree'; let registry: string[] = [] let trees: NodeT[] = [] @@ -22,6 +22,7 @@ if (links.length === 0) return registry = links trees = pathsToFileTree(registry) + trees = sortByType(trees) }) diff --git a/src/FileTree.ts b/src/FileTree.ts index da817ff..ba4be75 100644 --- a/src/FileTree.ts +++ b/src/FileTree.ts @@ -7,6 +7,16 @@ export type NodeT = { children: NodeT[] } +export function sortByType(list: NodeT[]): NodeT[] { + const directory = list.filter(a => a.href === '') + const files = list.filter(a => a.href !== '') + return [...directory, ...files] +} + +export function sortByName(list: NodeT[]): NodeT[] { + return list.sort() +} + // Trie: https://en.wikipedia.org/wiki/Trie function findNodeT(tree: NodeT[], key: string): NodeT | null { for (const node of tree) { @@ -43,9 +53,12 @@ export function pathsToFileTree(paths: string[]): NodeT[] { let parent: NodeT | null = null for (let i = 0; i < sep.length; ++i) { key += '/' + sep[i] + const name = sep[i].split('_') + .map(v => v[0].toUpperCase() + v.slice(1, v.length)).join(' ') + .split('-').map(v => v[0].toUpperCase() + v.slice(1, v.length)).join('. ') const node: NodeT = { key: key, - name: sep[i].split('_').map(v => v[0].toUpperCase() + v.slice(1, v.length)).join(' '), + name: name, level: i, href: i === sep.length - 1 ? path : '', parent: parent, diff --git a/src/main.ts b/src/main.ts index 8a909a1..2b4e1de 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,16 @@ import './app.css' import App from './App.svelte' +const APP_NAME = __VITE_ENV__.APP_NAME +const VERSION = __VITE_ENV__.VERSION +const COMMIT_HASH = __VITE_ENV__.COMMIT_HASH +const BUILD_DATE = __VITE_ENV__.BUILD_DATE + +console.log(`${APP_NAME} - v${VERSION}-${COMMIT_HASH.slice(0, 7)} +build date: ${BUILD_DATE}`.trim()) + const app = new App({ - target: document.getElementById('app'), + target: document.getElementById('app')!, }) export default app diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 4078e74..2674256 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,2 +1,13 @@ /// /// + +declare const __VITE_ENV__ : { + MODE: string + APP_NAME: string + VERSION: string + AUTHOR: string + DESCRIPTION: string + HOMEPAGE: string + COMMIT_HASH: string + BUILD_DATE: string +} diff --git a/vite.config.ts b/vite.config.ts index d701969..2b0c064 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,21 @@ import { defineConfig } from 'vite' import { svelte } from '@sveltejs/vite-plugin-svelte' +const env = { + MODE: process.env.NODE_ENV, + APP_NAME: 'Maths', + VERSION: process.env.npm_package_version, + AUTHOR: process.env.npm_package_author_name, + DESCRIPTION: process.env.npm_package_description, + HOMEPAGE: process.env.npm_package_homepage, + COMMIT_HASH: process.env.GITHUB_SHA || 'development', + BUILD_DATE: new Date().toISOString() +} + // https://vitejs.dev/config/ export default defineConfig({ plugins: [svelte()], + define: { + __VITE_ENV__: JSON.stringify(env) + } })