oddmisc 1.1.2 → 1.1.3

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.
Files changed (2) hide show
  1. package/README.md +123 -132
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,133 +1,124 @@
1
- # oddmisc
2
-
3
- 杂七杂八奇怪小工具 npm 包
4
-
5
- [![npm version](https://img.shields.io/npm/v/oddmisc.svg)](https://www.npmjs.com/package/oddmisc)
6
- [![License](https://img.shields.io/npm/l/oddmisc.svg)](https://github.com/yCENzh/oddmisc/blob/main/LICENSE)
7
-
8
- ## 安装
9
-
10
- ```bash
11
- npm install oddmisc
12
- # 或
13
- pnpm add oddmisc
14
- # 或
15
- yarn add oddmisc
16
- ```
17
-
18
- ## 快速开始
19
-
20
- ### 基本使用
21
-
22
- ```javascript
23
- import { createUmamiClient } from 'oddmisc';
24
-
25
- // 创建客户端
26
- const client = createUmamiClient({
27
- shareUrl: 'https://your-umami-instance.com/share/your-share-id'
28
- });
29
-
30
- // 获取页面访问统计
31
- const stats = await client.getPageStats('/about');
32
- console.log(`页面浏览量: ${stats.pageviews}, 访客数: ${stats.visitors}`);
33
-
34
- // 获取网站整体统计
35
- const siteStats = await client.getSiteStats();
36
- console.log(`总浏览量: ${siteStats.pageviews}, 总访客数: ${siteStats.visitors}`);
37
- ```
38
-
39
- ### Astro 集成
40
-
41
- 在 `astro.config.mjs` 中配置:
42
-
43
- ```javascript
44
- import { defineConfig } from 'astro/config';
45
- import { umami } from 'oddmisc';
46
-
47
- export default defineConfig({
48
- integrations: [
49
- umami({
50
- shareUrl: 'https://your-umami-instance.com/share/your-share-id',
51
- timezone: 'Asia/Shanghai',
52
- enableCache: true,
53
- cacheTTL: 3600000 // 1小时
54
- })
55
- ]
56
- });
57
- ```
58
-
59
- 然后在前端代码中使用:
60
-
61
- ```javascript
62
- // 全局可用
63
- const stats = await window.oddmisc.getStats('/some-page');
64
- const siteStats = await window.oddmisc.getSiteStats();
65
- ```
66
-
67
- ## API 参考
68
-
69
- ### UmamiClient
70
-
71
- #### 构造函数
72
- ```javascript
73
- const client = createUmamiClient(config);
74
- ```
75
-
76
- #### 配置选项
77
- ```javascript
78
- const config = {
79
- shareUrl: 'https://umami.example.com/share/abc123', // 必需
80
- timezone: 'Asia/Shanghai', // 可选,默认 'Asia/Shanghai'
81
- enableCache: true, // 可选,默认 true
82
- cacheTTL: 3600000 // 可选,默认 1小时(毫秒)
83
- };
84
- ```
85
-
86
- #### 方法
87
-
88
- - `getPageStats(path, options)` - 获取指定页面统计
89
- - `getPageStatsByUrl(url, options)` - 通过 URL 获取页面统计
90
- - `getSiteStats(options)` - 获取网站整体统计
91
- - `clearCache()` - 清除缓存
92
- - `getConfig()` - 获取当前配置
93
- - `updateConfig(newConfig)` - 更新配置
94
-
95
- ### Astro 集成
96
-
97
- ```javascript
98
- umami(options: UmamiIntegrationOptions)
99
- ```
100
-
101
- 选项:
102
- ```javascript
103
- interface UmamiIntegrationOptions {
104
- shareUrl: string; // Umami 分享链接
105
- timezone?: string; // 时区,默认 'Asia/Shanghai'
106
- enableCache?: boolean; // 启用缓存,默认 true
107
- cacheTTL?: number; // 缓存时间,单位毫秒
108
- }
109
- ```
110
-
111
- ## 支持的 Umami URL 格式
112
-
113
- - `https://umami.example.com/share/abc123`
114
- - `https://cloud.umami.is/analytics/us/share/abc123`
115
- - `https://umami.example.com/analytics/share/abc123`
116
-
117
- ## 浏览器兼容性
118
-
119
- - 现代浏览器(Chrome 60+, Firefox 60+, Safari 12+)
120
- - 支持 localStorage 的环境
121
-
122
- ## License
123
-
124
- MIT © yCENzh
125
-
126
- ## 贡献
127
-
128
- 欢迎提交 Issue 和 Pull Request!
129
-
130
- ## 相关链接
131
-
132
- - [Umami 官网](https://umami.is/)
1
+ # oddmisc
2
+
3
+ 杂七杂八奇怪小工具 npm 包
4
+
5
+ [![npm version](https://img.shields.io/npm/v/oddmisc.svg)](https://www.npmjs.com/package/oddmisc)
6
+ [![License](https://img.shields.io/npm/l/oddmisc.svg)](https://github.com/yCENzh/oddmisc/blob/main/LICENSE)
7
+
8
+ ## 安装
9
+
10
+ ```bash
11
+ npm install oddmisc
12
+ # 或
13
+ pnpm add oddmisc
14
+ # 或
15
+ yarn add oddmisc
16
+ ```
17
+
18
+ ## 快速开始
19
+
20
+ ### 基本使用
21
+
22
+ ```javascript
23
+ import { createUmamiClient } from 'oddmisc';
24
+
25
+ // 创建客户端
26
+ const client = createUmamiClient({
27
+ shareUrl: 'https://your-umami-instance.com/share/your-share-id'
28
+ });
29
+
30
+ // 获取页面访问统计
31
+ const stats = await client.getPageStats('/about');
32
+ console.log(`页面浏览量: ${stats.pageviews}, 访客数: ${stats.visitors}, 访问次数: ${stats.visits}`);
33
+
34
+ // 获取网站整体统计
35
+ const siteStats = await client.getSiteStats();
36
+ console.log(`总浏览量: ${siteStats.pageviews}, 总访客数: ${siteStats.visitors}, 总访问次数: ${siteStats.visits}`);
37
+ ```
38
+
39
+ ### Astro 集成
40
+
41
+ 在 `astro.config.mjs` 中配置:
42
+
43
+ ```javascript
44
+ import { defineConfig } from 'astro/config';
45
+ import { umami } from 'oddmisc';
46
+
47
+ export default defineConfig({
48
+ integrations: [
49
+ umami({
50
+ shareUrl: 'https://your-umami-instance.com/share/your-share-id'
51
+ })
52
+ ]
53
+ });
54
+ ```
55
+
56
+ 然后在前端代码中使用:
57
+
58
+ ```javascript
59
+ // 全局可用
60
+ const stats = await window.oddmisc.getStats('/some-page');
61
+ const siteStats = await window.oddmisc.getSiteStats();
62
+ ```
63
+
64
+ ## API 参考
65
+
66
+ ### UmamiClient
67
+
68
+ #### 构造函数
69
+ ```javascript
70
+ const client = createUmamiClient(config);
71
+ ```
72
+
73
+ #### 配置选项
74
+ ```javascript
75
+ const config = {
76
+ shareUrl: 'https://umami.example.com/share/abc123' // 必需
77
+ };
78
+ ```
79
+
80
+ #### 方法
81
+
82
+ - `getPageStats(path)` - 获取指定页面统计
83
+ - `getPageStatsByUrl(url)` - 通过 URL 获取页面统计
84
+ - `getSiteStats()` - 获取网站整体统计
85
+ - `clearCache()` - 清除缓存
86
+ - `getConfig()` - 获取当前配置
87
+ - `updateConfig(newConfig)` - 更新配置
88
+
89
+ ### Astro 集成
90
+
91
+ ```javascript
92
+ umami(options: UmamiIntegrationOptions)
93
+ ```
94
+
95
+ 选项:
96
+ ```javascript
97
+ interface UmamiIntegrationOptions {
98
+ shareUrl: string; // Umami 分享链接
99
+ }
100
+ ```
101
+
102
+ ## 支持的 Umami URL 格式
103
+
104
+ - `https://umami.example.com/share/abc123`
105
+ - `https://cloud.umami.is/analytics/us/share/abc123`
106
+ - `https://umami.example.com/analytics/share/abc123`
107
+
108
+ ## 浏览器兼容性
109
+
110
+ - 现代浏览器(Chrome 60+, Firefox 60+, Safari 12+)
111
+ - 支持 localStorage 的环境
112
+
113
+ ## License
114
+
115
+ MIT © yCENzh
116
+
117
+ ## 贡献
118
+
119
+ 欢迎提交 Issue Pull Request!
120
+
121
+ ## 相关链接
122
+
123
+ - [Umami 官网](https://umami.is/)
133
124
  - [GitHub 仓库](https://github.com/yCENzh/oddmisc)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oddmisc",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "杂七杂八奇怪小工具 npm 包",
5
5
  "homepage": "https://github.com/yCENzh/oddmisc#readme",
6
6
  "bugs": {