@umami/shiso 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +11 -0
- package/.prettierrc.json +7 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/index.css +158 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +335 -0
- package/dist/index.mjs +302 -0
- package/dts.mjs +8 -0
- package/esbuild.mjs +36 -0
- package/next.config.ts +15 -0
- package/package.json +83 -0
- package/public/leaf.png +0 -0
- package/public/leaf.svg +1 -0
- package/src/app/Footer.tsx +14 -0
- package/src/app/Header.tsx +14 -0
- package/src/app/blog/[[...id]]/page.tsx +8 -0
- package/src/app/docs/[[...id]]/page.tsx +8 -0
- package/src/app/layout.tsx +41 -0
- package/src/app/page.tsx +25 -0
- package/src/assets/leaf.svg +1 -0
- package/src/components/Footer.module.css +0 -0
- package/src/components/Footer.tsx +1 -0
- package/src/components/Header.module.css +0 -0
- package/src/components/Header.tsx +0 -0
- package/src/components/Markdown.tsx +21 -0
- package/src/components/Shiso.tsx +19 -0
- package/src/components/blog/Blog.module.css +0 -0
- package/src/components/blog/Blog.tsx +21 -0
- package/src/components/docs/Callout.module.css +6 -0
- package/src/components/docs/Callout.tsx +18 -0
- package/src/components/docs/CodeBlock.module.css +37 -0
- package/src/components/docs/CodeBlock.tsx +30 -0
- package/src/components/docs/ContentArea.module.css +63 -0
- package/src/components/docs/ContentArea.tsx +27 -0
- package/src/components/docs/Docs.tsx +50 -0
- package/src/components/docs/Note.tsx +5 -0
- package/src/components/docs/PageLinks.module.css +49 -0
- package/src/components/docs/PageLinks.tsx +49 -0
- package/src/components/docs/SideNav.module.css +32 -0
- package/src/components/docs/SideNav.tsx +46 -0
- package/src/components/docs/TopNav.tsx +25 -0
- package/src/components/icons/Leaf.tsx +15 -0
- package/src/components/icons/index.ts +1 -0
- package/src/components/index.ts +8 -0
- package/src/content/blog/index.mdx +5 -0
- package/src/content/docs/components/index.mdx +1 -0
- package/src/content/docs/components.mdx +5 -0
- package/src/content/docs/configuration.mdx +81 -0
- package/src/content/docs/index.mdx +11 -0
- package/src/content/docs/installation.mdx +38 -0
- package/src/content/docs/writing-content.mdx +95 -0
- package/src/declarations.d.ts +3 -0
- package/src/index.ts +5 -0
- package/src/lib/content.ts +61 -0
- package/src/lib/next.tsx +46 -0
- package/src/lib/types.ts +10 -0
- package/src/shiso.config.json +59 -0
- package/tsconfig.build.json +24 -0
- package/tsconfig.json +41 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Tracker functions
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The Umami tracker exposes a function that you can call on your website if you want
|
|
6
|
+
more control over your tracking. By default everything is automatically collected, but you can
|
|
7
|
+
disable this using `data-auto-track="false"` and sending the data yourself.
|
|
8
|
+
See [Tracker configuration](/docs/tracker-configuration).
|
|
9
|
+
|
|
10
|
+
## Functions
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
umami.track(payload: object);
|
|
14
|
+
|
|
15
|
+
umami.track(event_name: string, event_data: object);
|
|
16
|
+
|
|
17
|
+
umami.identify(session_data: object);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Pageviews
|
|
21
|
+
|
|
22
|
+
Tracks a page view.
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
umami.track();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
By default the tracker automatically collects the following properties:
|
|
29
|
+
|
|
30
|
+
- `hostname` - Hostname of server
|
|
31
|
+
- `language` - Browser language
|
|
32
|
+
- `referrer` - Page referrer
|
|
33
|
+
- `screen` - Screen dimensions (eg. 1920x1080)
|
|
34
|
+
- `title` - Page title
|
|
35
|
+
- `url` - Page url
|
|
36
|
+
- `website` - Website ID (required)
|
|
37
|
+
|
|
38
|
+
If you wish to send your own custom payload, pass in an object to the function:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
umami.track({ website: 'e676c9b4-11e4-4ef1-a4d7-87001773e9f2', url: '/home', title: 'Home page' });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The above will only send the properties `website`, `url` and `title`. If you want to include existing properties, pass in a function:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
umami.track(props => ({ ...props, url: '/home', title: 'Home page' }));
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Events
|
|
51
|
+
|
|
52
|
+
Tracks an event with a given name.
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
umami.track('signup-button');
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Event Data
|
|
59
|
+
|
|
60
|
+
Tracks an event with dynamic data.
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
umami.track('signup-button', { name: 'newsletter', id: 123 });
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
When tracking events, the default properties are included in the payload.
|
|
67
|
+
This is equivalent to running:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
umami.track(props => ({
|
|
71
|
+
...props,
|
|
72
|
+
name: 'signup-button',
|
|
73
|
+
data: {
|
|
74
|
+
name: 'newsletter',
|
|
75
|
+
id: 123,
|
|
76
|
+
},
|
|
77
|
+
}));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Event Data Limits
|
|
81
|
+
|
|
82
|
+
Event Data can work with any JSON data. There are a few rules in place to maintain performance.
|
|
83
|
+
|
|
84
|
+
- Numbers have a max precision of 4.
|
|
85
|
+
- Strings have a max length of 500.
|
|
86
|
+
- Arrays are converted to a String, with the same max length of 500.
|
|
87
|
+
- Objects have a max of 50 properties. Arrays are considered 1 property.
|
|
88
|
+
|
|
89
|
+
## Session Data
|
|
90
|
+
|
|
91
|
+
Tracks a session with dynamic data. You would call the identity function from the tracker script to save data about the current session.
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
umami.identify({ email: 'bob@aol.com' });
|
|
95
|
+
```
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { cache } from 'react';
|
|
2
|
+
import matter from 'gray-matter';
|
|
3
|
+
import recursive from 'recursive-readdir';
|
|
4
|
+
import { firstBy } from 'thenby';
|
|
5
|
+
import fs from 'node:fs/promises';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
export const getFiles = cache(async (folder: string) => {
|
|
9
|
+
const dir = path.resolve(folder);
|
|
10
|
+
const files = await recursive(dir);
|
|
11
|
+
|
|
12
|
+
return Promise.all(
|
|
13
|
+
files
|
|
14
|
+
.filter((file: string) => path.extname(file) === '.mdx')
|
|
15
|
+
.map(async (file: string) => {
|
|
16
|
+
const postContent = await fs.readFile(file, 'utf8');
|
|
17
|
+
const { data, content } = matter(postContent);
|
|
18
|
+
|
|
19
|
+
const id = file.replace('.mdx', '').replace(dir, '').replace(/\\/g, '/').replace(/^\//, '');
|
|
20
|
+
const anchors: { name: string; id: string; size: number }[] = [];
|
|
21
|
+
const body = content
|
|
22
|
+
.split('\n')
|
|
23
|
+
.map(line => {
|
|
24
|
+
const match = line.match(/(#+)\s+(.*)/);
|
|
25
|
+
if (match) {
|
|
26
|
+
const [, num, name] = match;
|
|
27
|
+
const id = name.toLowerCase().replace(/\s+/g, '-');
|
|
28
|
+
const size = num.length;
|
|
29
|
+
|
|
30
|
+
anchors.push({ name, id, size });
|
|
31
|
+
|
|
32
|
+
return `<h${size} id="${id}">${name.replace(/\{|\}/g, '')}</h${size}>`;
|
|
33
|
+
}
|
|
34
|
+
return line;
|
|
35
|
+
})
|
|
36
|
+
.join('\n');
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
meta: data,
|
|
40
|
+
id,
|
|
41
|
+
body,
|
|
42
|
+
anchors,
|
|
43
|
+
} as any;
|
|
44
|
+
}),
|
|
45
|
+
).then(posts => posts.sort(firstBy('date', 'desc')));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export async function getFile(id: string, folder: string) {
|
|
49
|
+
const files = await getFiles(folder);
|
|
50
|
+
|
|
51
|
+
return files.find(file => file?.id === id);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function getContent(params: { id: string[] }, folder: string) {
|
|
55
|
+
const { id = [] } = params;
|
|
56
|
+
const name = id?.length ? id.join('/') : 'index';
|
|
57
|
+
|
|
58
|
+
return getFile(name, folder);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default getFile;
|
package/src/lib/next.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Metadata } from 'next';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { Docs } from '@/components/docs/Docs';
|
|
4
|
+
import { Blog } from '@/components/blog/Blog';
|
|
5
|
+
import { getContent } from '@/lib/content';
|
|
6
|
+
import { ShisoConfig } from '@/components/Shiso';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_CONTENT_DIR = './src/content';
|
|
9
|
+
|
|
10
|
+
const components = {
|
|
11
|
+
docs: Docs,
|
|
12
|
+
blog: Blog,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default (config: ShisoConfig) => {
|
|
16
|
+
const { contentDir = DEFAULT_CONTENT_DIR } = config || {};
|
|
17
|
+
|
|
18
|
+
const getMetadata = ({ title }: { title: string }) => {
|
|
19
|
+
return async ({ params }: { params: Promise<{ id: string[] }> }): Promise<Metadata> => {
|
|
20
|
+
const content = await getContent(await params, contentDir);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
title: {
|
|
24
|
+
absolute: `${content?.meta?.title} – ${title}`,
|
|
25
|
+
default: title,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const renderPage = ({ type }: { type: string }) => {
|
|
32
|
+
const folder = path.resolve(process.cwd(), contentDir, type);
|
|
33
|
+
|
|
34
|
+
return async ({ params }: { params: Promise<{ id: string[] }> }) => {
|
|
35
|
+
const content = await getContent(await params, folder);
|
|
36
|
+
const Component = components[type];
|
|
37
|
+
|
|
38
|
+
return Component && <Component content={content} config={config} />;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
getMetadata,
|
|
44
|
+
renderPage,
|
|
45
|
+
};
|
|
46
|
+
};
|
package/src/lib/types.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contentDir": "./src/content",
|
|
3
|
+
"docs": {
|
|
4
|
+
"title": "Shiso",
|
|
5
|
+
"tabs": [
|
|
6
|
+
{
|
|
7
|
+
"id": "docs",
|
|
8
|
+
"label": "Documentation",
|
|
9
|
+
"url": "/docs"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"id": "components",
|
|
13
|
+
"label": "Components",
|
|
14
|
+
"url": "/docs/components"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"navigation": {
|
|
18
|
+
"docs": [
|
|
19
|
+
{
|
|
20
|
+
"group": "Getting started",
|
|
21
|
+
"pages": [
|
|
22
|
+
{
|
|
23
|
+
"label": "Overview",
|
|
24
|
+
"url": "/docs"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"label": "Installation",
|
|
28
|
+
"url": "/docs/installation"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"label": "Configuration",
|
|
32
|
+
"url": "/docs/configuration"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"group": "Basics",
|
|
38
|
+
"pages": [
|
|
39
|
+
{
|
|
40
|
+
"label": "Writing content",
|
|
41
|
+
"url": "/docs/writing-content"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"components": [
|
|
47
|
+
{
|
|
48
|
+
"group": "Components",
|
|
49
|
+
"pages": [
|
|
50
|
+
{
|
|
51
|
+
"label": "Overview",
|
|
52
|
+
"url": "/docs/components"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"noImplicitAny": false,
|
|
5
|
+
"emitDeclarationOnly": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"rootDir": "./src",
|
|
12
|
+
"outDir": "./types",
|
|
13
|
+
"module": "esnext",
|
|
14
|
+
"moduleResolution": "bundler",
|
|
15
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
16
|
+
"jsx": "preserve",
|
|
17
|
+
"paths": {
|
|
18
|
+
"@/*": ["./src/*"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"include": ["src/components/**/*"],
|
|
22
|
+
"exclude": ["node_modules"]
|
|
23
|
+
}
|
|
24
|
+
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": [
|
|
4
|
+
"dom",
|
|
5
|
+
"dom.iterable",
|
|
6
|
+
"esnext"
|
|
7
|
+
],
|
|
8
|
+
"noImplicitAny": false,
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"module": "esnext",
|
|
15
|
+
"moduleResolution": "bundler",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"jsx": "preserve",
|
|
19
|
+
"incremental": true,
|
|
20
|
+
"plugins": [
|
|
21
|
+
{
|
|
22
|
+
"name": "next"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"paths": {
|
|
26
|
+
"@/*": [
|
|
27
|
+
"./src/*"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"target": "ES2017"
|
|
31
|
+
},
|
|
32
|
+
"include": [
|
|
33
|
+
"next-env.d.ts",
|
|
34
|
+
"**/*.ts",
|
|
35
|
+
"**/*.tsx",
|
|
36
|
+
".next/types/**/*.ts"
|
|
37
|
+
],
|
|
38
|
+
"exclude": [
|
|
39
|
+
"node_modules"
|
|
40
|
+
]
|
|
41
|
+
}
|