Skip to content

Commit

Permalink
Show children count
Browse files Browse the repository at this point in the history
Add Linjär Algebra
  • Loading branch information
mnerv committed Nov 4, 2023
1 parent ff75df7 commit e78f01f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []
Expand All @@ -22,6 +22,7 @@
if (links.length === 0) return
registry = links
trees = pathsToFileTree(registry)
trees = sortByType(trees)
})
</script>

Expand Down
15 changes: 14 additions & 1 deletion src/FileTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />

declare const __VITE_ENV__ : {
MODE: string
APP_NAME: string
VERSION: string
AUTHOR: string
DESCRIPTION: string
HOMEPAGE: string
COMMIT_HASH: string
BUILD_DATE: string
}
14 changes: 14 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -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)
}
})

0 comments on commit e78f01f

Please sign in to comment.