aboutsummaryrefslogtreecommitdiff
path: root/templates/Default/index.tsx
blob: 8902bf81b17e58f4f944869a40061545151617b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import clsx from "clsx";
import React, { FC } from "react";
import { Breadcrumbs, LinkCrumb } from "../../components/Breadcrumbs";
import Viewport from "../../components/ViewPort";
import styles from './default.module.scss';

export type DefaultPage = {
    className?: string;
    path?: string;
};

export type RelPathProps = {
    path: string;
};

const RelPath : FC<RelPathProps> = ({path, ...props}) => {
    const _path = path[path.length - 1] === '/' ? path.substr(0, path.length - 1) : path;
    
    const parts = _path.split('/');
    const rels = [''];
    
    for(let i = 1; i < parts.length; i++) {
        rels.push([rels[i - 1], parts[i]].join('/'));
    }
    
    rels[0] = '/';
    parts[0] = 'flu0r1ne.net';
    
    return (
        <Breadcrumbs>
            {rels.map((relHref, i) => (
                <LinkCrumb key={relHref} href={relHref}>
                    {parts[i]} 
                </LinkCrumb>
            ))}
        </Breadcrumbs>
    );
}

const DefaultPage : FC<DefaultPage> = ({className, children, path, ...props}) => (
    <Viewport
        className={clsx(styles.viewportOverrides, className)}
    >
        {path !== undefined ? <RelPath path={path!} /> : undefined}
        {children}
    </Viewport>
);

export default DefaultPage;