@jant/core 1.1.0 → 1.3.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/bin/commands/site/import.js +2 -1
- package/bin/lib/site-snapshot.js +10 -0
- package/dist/{app-CKQ9PqAr.js → app-C8dETvgL.js} +9267 -5697
- package/dist/client/.vite/manifest.json +82 -93
- package/dist/client/_assets/chunks/{confirm-CMe01lne.js → confirm-BQebcuNB.js} +1 -1
- package/dist/client/_assets/chunks/{create-editor-BQkrw8Ax.js → create-editor-B8KuszlS.js} +38 -38
- package/dist/client/_assets/chunks/footnote-rail-DUrqz0Py.js +2 -0
- package/dist/client/_assets/chunks/{jant-locale-picker-2L4rkDaz.js → jant-locale-picker-CLq0iKDH.js} +1 -1
- package/dist/client/_assets/chunks/lit-BN4mrI3j.js +2 -0
- package/dist/client/_assets/chunks/{settings-paths-B0bNUaih.js → settings-paths-_fry4yWW.js} +1 -1
- package/dist/client/_assets/chunks/{slug-format-CYmQE5ln.js → slug-format-bcJ2ozr4.js} +1 -1
- package/dist/client/_assets/chunks/sortable-list-Bz2Na2E9.js +2 -0
- package/dist/client/_assets/chunks/types-DrYFqJH2.js +1 -0
- package/dist/client/_assets/chunks/{unsafe-html-CWos3v6N.js → unsafe-html-OJ9m154w.js} +1 -1
- package/dist/client/_assets/chunks/unsafe-svg-DVJ4NPcb.js +1 -0
- package/dist/client/_assets/client-CoNHvipV.css +2 -0
- package/dist/client/_assets/{client-auth-CG55rWb5.js → client-auth-CbnZkLJ6.js} +99 -129
- package/dist/client/_assets/{client-author-CGVvrNZ8.css → client-author-2WYBkgni.css} +1 -1
- package/dist/client/_assets/client-compose-DYtDlYm-.js +2008 -0
- package/dist/client/_assets/{client-manage-DnYdQAhf.js → client-manage-BODyYP5Z.js} +157 -157
- package/dist/client/_assets/client-pq6sVS7y.js +354 -0
- package/dist/client/_assets/{client-settings-CHgsIqXJ.js → client-settings-DDpe_tXJ.js} +166 -166
- package/dist/client/_assets/client-share-B9OsXx9p.js +149 -0
- package/dist/{constants-DEgyqWDl.js → constants-C2CdWAqt.js} +55 -5
- package/dist/index.js +1 -1
- package/dist/node.js +3 -2
- package/package.json +2 -1
- package/src/app.tsx +9 -0
- package/src/client/components/compose-types.ts +6 -1
- package/src/client/components/jant-compose-dialog.ts +26 -4
- package/src/client/components/jant-compose-editor.ts +30 -0
- package/src/client/components/jant-compose-fullscreen.ts +1 -0
- package/src/client/components/jant-media-lightbox.ts +18 -3
- package/src/client/components/jant-nav-manager.ts +2 -0
- package/src/client/components/jant-post-menu.ts +42 -89
- package/src/client/components/nav-manager-types.ts +2 -0
- package/src/client/components/settings-types.ts +1 -1
- package/src/client/compose-bridge.ts +61 -1
- package/src/client/feed-video-player.ts +6 -0
- package/src/client/list-views.ts +382 -0
- package/src/client/media-lightbox-events.ts +12 -0
- package/src/client/runtime-paths.ts +12 -0
- package/src/client/share-capture.ts +63 -0
- package/src/client/share-launch.ts +36 -9
- package/src/client/tiptap/bubble-menu.ts +25 -2
- package/src/client/tiptap/create-editor.ts +6 -0
- package/src/client/tiptap/embed-node.ts +3 -1
- package/src/client/tiptap/extensions.ts +4 -0
- package/src/client/tiptap/html-block-node.ts +3 -1
- package/src/client/tiptap/image-node.ts +3 -1
- package/src/client/video-processor.ts +106 -52
- package/src/client/view-confirm.ts +136 -0
- package/src/client.ts +2 -0
- package/src/db/migrations/0035_brainy_next_avengers.sql +9 -0
- package/src/db/migrations/0036_gorgeous_smasher.sql +7 -0
- package/src/db/migrations/0037_round_post.sql +16 -0
- package/src/db/migrations/0038_flashy_changeling.sql +15 -0
- package/src/db/migrations/0039_mixed_sister_grimm.sql +1 -0
- package/src/db/migrations/meta/0035_snapshot.json +2877 -0
- package/src/db/migrations/meta/0036_snapshot.json +2924 -0
- package/src/db/migrations/meta/0037_snapshot.json +2932 -0
- package/src/db/migrations/meta/0038_snapshot.json +2924 -0
- package/src/db/migrations/meta/0039_snapshot.json +2931 -0
- package/src/db/migrations/meta/_journal.json +35 -0
- package/src/db/migrations/pg/0033_cute_magdalene.sql +10 -0
- package/src/db/migrations/pg/0034_material_agent_brand.sql +8 -0
- package/src/db/migrations/pg/0035_flimsy_outlaw_kid.sql +3 -0
- package/src/db/migrations/pg/0036_milky_wolverine.sql +5 -0
- package/src/db/migrations/pg/0037_fuzzy_hammerhead.sql +1 -0
- package/src/db/migrations/pg/meta/0033_snapshot.json +3719 -0
- package/src/db/migrations/pg/meta/0034_snapshot.json +3766 -0
- package/src/db/migrations/pg/meta/0035_snapshot.json +3773 -0
- package/src/db/migrations/pg/meta/0036_snapshot.json +3766 -0
- package/src/db/migrations/pg/meta/0037_snapshot.json +3772 -0
- package/src/db/migrations/pg/meta/_journal.json +35 -0
- package/src/db/pg/schema.ts +41 -0
- package/src/db/post-visibility.ts +37 -6
- package/src/db/schema.ts +64 -0
- package/src/i18n/locales/glossary.zh-Hans.yml +4 -0
- package/src/i18n/locales/glossary.zh-Hant.yml +4 -0
- package/src/i18n/locales/public/en.po +26 -7
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +25 -6
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +25 -6
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +159 -0
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +159 -0
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +159 -0
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/lib/api-public-posts.ts +10 -0
- package/src/lib/env.ts +20 -0
- package/src/lib/feed-policy.ts +2 -2
- package/src/lib/filter-dimensions.ts +11 -4
- package/src/lib/github-app-state.ts +1 -1
- package/src/lib/github-app.ts +183 -1
- package/src/lib/hugo-markdown.ts +7 -0
- package/src/lib/icons.ts +2 -0
- package/src/lib/link-preview.ts +499 -0
- package/src/lib/list-views.ts +117 -0
- package/src/lib/markdown-manager.ts +169 -2
- package/src/lib/navigation.ts +1 -1
- package/src/lib/post-meta.ts +13 -3
- package/src/lib/referrer-aliases.ts +311 -0
- package/src/lib/render.tsx +10 -0
- package/src/lib/resolve-config.ts +14 -0
- package/src/lib/share-card.ts +4 -3
- package/src/lib/summary.ts +152 -54
- package/src/lib/thread-query.ts +6 -2
- package/src/lib/timeline.ts +12 -11
- package/src/lib/tiptap-render.ts +1 -0
- package/src/lib/upload.ts +21 -1
- package/src/lib/url-fetch.ts +291 -74
- package/src/lib/video-playback.ts +55 -0
- package/src/lib/view-buffer.ts +201 -0
- package/src/lib/view-counting.ts +540 -0
- package/src/lib/view-token.ts +199 -0
- package/src/lib/view.ts +30 -1
- package/src/middleware/view-counter.ts +145 -0
- package/src/node/runtime.ts +4 -0
- package/src/preset.css +36 -17
- package/src/routes/api/media.ts +21 -3
- package/src/routes/api/search.ts +1 -1
- package/src/routes/dash/settings.tsx +434 -169
- package/src/routes/feed/sitemap.ts +1 -1
- package/src/routes/pages/archive.tsx +26 -19
- package/src/routes/pages/collection.tsx +9 -3
- package/src/routes/pages/collections.tsx +1 -0
- package/src/routes/pages/featured.tsx +1 -0
- package/src/routes/pages/home.tsx +1 -0
- package/src/routes/pages/page.tsx +18 -3
- package/src/routes/pages/search.tsx +3 -3
- package/src/routes/pages/smart-collection.tsx +2 -0
- package/src/routes/pages/subscribe.tsx +1 -0
- package/src/routes/view-confirm.ts +71 -0
- package/src/services/collection.ts +1 -1
- package/src/services/export-theme/assets/client-site.js +19 -19
- package/src/services/export-theme/layouts/archive/list.html +4 -2
- package/src/services/export-theme/layouts/partials/collection-members.html +4 -3
- package/src/services/export-theme/layouts/partials/featured-members.html +3 -3
- package/src/services/export-theme/layouts/partials/head.html +2 -0
- package/src/services/export-theme/layouts/partials/latest-members.html +4 -4
- package/src/services/export-theme/layouts/partials/post-card.html +1 -9
- package/src/services/export-theme/layouts/partials/reply.html +1 -9
- package/src/services/export-theme/layouts/partials/smart-collection-members.html +4 -3
- package/src/services/export-theme/layouts/post/list.html +1 -9
- package/src/services/export-theme/styles/main.css +41 -47
- package/src/services/export.ts +12 -3
- package/src/services/index.ts +17 -0
- package/src/services/mcp.ts +36 -6
- package/src/services/media.ts +63 -0
- package/src/services/navigation.ts +9 -4
- package/src/services/post.ts +102 -112
- package/src/services/search.ts +22 -7
- package/src/services/smart-collection.ts +3 -3
- package/src/services/stats.ts +1137 -0
- package/src/services/thread.ts +6 -2
- package/src/styles/components-author.css +242 -3
- package/src/styles/components.css +11 -3
- package/src/styles/tokens.css +89 -55
- package/src/styles/ui-author.css +140 -353
- package/src/styles/ui.css +90 -45
- package/src/types/app-context.ts +9 -0
- package/src/types/bindings.ts +5 -0
- package/src/types/config.ts +54 -0
- package/src/types/constants.ts +68 -4
- package/src/types/entities.ts +1 -0
- package/src/types/views.ts +8 -0
- package/src/ui/compose/ComposeDialog.tsx +26 -1
- package/src/ui/dash/StatusBadge.tsx +11 -0
- package/src/ui/dash/appearance/FontThemeContent.tsx +1 -1
- package/src/ui/dash/appearance/NavigationContent.tsx +8 -0
- package/src/ui/dash/settings/SettingsRootContent.tsx +24 -6
- package/src/ui/dash/settings/StatsContent.tsx +855 -0
- package/src/ui/feed/LinkCard.tsx +19 -2
- package/src/ui/feed/PostStatusBadges.tsx +19 -3
- package/src/ui/feed/TimelineFeed.tsx +3 -0
- package/src/ui/font-themes.ts +56 -6
- package/src/ui/layouts/BaseLayout.tsx +4 -2
- package/src/ui/layouts/SiteLayout.tsx +8 -3
- package/src/ui/pages/ArchivePage.tsx +1 -0
- package/src/ui/shared/MediaGallery.tsx +19 -3
- package/src/ui/shared/PostFooter.tsx +1 -22
- package/src/ui/shared/custom-icons.ts +5 -5
- package/dist/client/_assets/chunks/footnote-rail-B08scyhW.js +0 -2
- package/dist/client/_assets/chunks/lit-Bw_voPoW.js +0 -2
- package/dist/client/_assets/chunks/runtime-paths-y0_gHowM.js +0 -1
- package/dist/client/_assets/chunks/sortable-list-t11Ma1Ek.js +0 -2
- package/dist/client/_assets/chunks/types-D5iF3H1a.js +0 -1
- package/dist/client/_assets/chunks/unsafe-svg-DZl-yjas.js +0 -1
- package/dist/client/_assets/client-B0-s9sqx.css +0 -2
- package/dist/client/_assets/client-Dp46QSht.js +0 -354
- package/dist/client/_assets/client-compose-DkUTuavR.js +0 -2004
- package/dist/client/_assets/client-share-C59mOLJ1.js +0 -149
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stats: views by hour or by day, the most-viewed pages, and where readers
|
|
3
|
+
* came from.
|
|
4
|
+
*
|
|
5
|
+
* One quiet page of aggregates for the author. It shows a window of time and
|
|
6
|
+
* nothing beyond it — no lifetime total, no comparison with the window before
|
|
7
|
+
* — because a number to beat is the one social mechanic this page must not
|
|
8
|
+
* grow into. Today is the default and is drawn by the hour; a longer window
|
|
9
|
+
* by the day. When counting began inside the window, the page says so and the
|
|
10
|
+
* chart starts on that day: the days before were not counted, which is not
|
|
11
|
+
* the same as a month of zeros. Posts, collections and the site's own pages
|
|
12
|
+
* share one ranked list, since the question is what was read, not what kind
|
|
13
|
+
* of thing it was; a badge says the kind, and a bar behind each row says its
|
|
14
|
+
* share. Every page and every referrer in the lists opens on its own: a
|
|
15
|
+
* page with where its readers came from, a referrer with the pages it sent
|
|
16
|
+
* them to. Each hop drops the other dimension rather than stacking filters,
|
|
17
|
+
* since today's hours are kept for the site as a whole and a filtered chart
|
|
18
|
+
* would have nothing to draw. `services/stats.ts` has the policy behind the
|
|
19
|
+
* numbers.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { I18n } from "@lingui/core";
|
|
23
|
+
import { msg } from "@lingui/core/macro";
|
|
24
|
+
import { useLingui } from "../../../i18n/context.js";
|
|
25
|
+
import { toPublicPath } from "../../../lib/url.js";
|
|
26
|
+
import { VIEW_INTERNAL_REFERRER } from "../../../lib/view-counting.js";
|
|
27
|
+
import {
|
|
28
|
+
STATS_WINDOWS,
|
|
29
|
+
VIEW_COUNT_RETENTION_DAYS,
|
|
30
|
+
type StatsOverview,
|
|
31
|
+
type StatsPage,
|
|
32
|
+
type StatsPageDetail,
|
|
33
|
+
type StatsPageRow,
|
|
34
|
+
type StatsReferrerDetail,
|
|
35
|
+
type StatsReferrers,
|
|
36
|
+
type StatsSeries,
|
|
37
|
+
type StatsWindow,
|
|
38
|
+
} from "../../../services/stats.js";
|
|
39
|
+
import { FormatBadge } from "../FormatBadge.js";
|
|
40
|
+
|
|
41
|
+
export interface StatsContentProps {
|
|
42
|
+
/** Whether views are being counted; off means no numbers to show. */
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
days: StatsWindow;
|
|
45
|
+
/** The site over the window; `null` when stats are off or a detail is shown. */
|
|
46
|
+
overview: StatsOverview | null;
|
|
47
|
+
/** One page over the window, when the page is about one page. */
|
|
48
|
+
page: StatsPageDetail | null;
|
|
49
|
+
/** One referrer over the window, when the page is about one referrer. */
|
|
50
|
+
referrer: StatsReferrerDetail | null;
|
|
51
|
+
sitePathPrefix: string;
|
|
52
|
+
demoMode: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** What a stats address can be about besides the site: one page, or one referrer. */
|
|
56
|
+
type StatsTarget = { page: string } | { referrer: string };
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The address of the stats page for a window, and optionally one page or
|
|
60
|
+
* one referrer. A referrer key goes in verbatim, so Direct is `referrer=`
|
|
61
|
+
* and Internal `referrer=%2F`: these addresses live in the settings and
|
|
62
|
+
* are never shown.
|
|
63
|
+
*/
|
|
64
|
+
function statsHref(
|
|
65
|
+
sitePathPrefix: string,
|
|
66
|
+
days: StatsWindow,
|
|
67
|
+
target?: StatsTarget,
|
|
68
|
+
): string {
|
|
69
|
+
const params = new URLSearchParams();
|
|
70
|
+
if (target && "page" in target) params.set("page", target.page);
|
|
71
|
+
if (target && "referrer" in target) params.set("referrer", target.referrer);
|
|
72
|
+
params.set("days", String(days));
|
|
73
|
+
return `${toPublicPath("/settings/stats", sitePathPrefix)}?${params}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `Nov 8` for a day key, in the dashboard's locale. */
|
|
77
|
+
function formatDayLabel(day: string, locale: string): string {
|
|
78
|
+
const [year, month, date] = day.split("-").map(Number);
|
|
79
|
+
return new Intl.DateTimeFormat(locale, {
|
|
80
|
+
month: "short",
|
|
81
|
+
day: "numeric",
|
|
82
|
+
timeZone: "UTC",
|
|
83
|
+
}).format(new Date(Date.UTC(year ?? 1970, (month ?? 1) - 1, date ?? 1)));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `14:00` for an hour of the day, in the dashboard's locale. */
|
|
87
|
+
function formatHourLabel(hour: number, locale: string): string {
|
|
88
|
+
return new Intl.DateTimeFormat(locale, {
|
|
89
|
+
hour: "2-digit",
|
|
90
|
+
minute: "2-digit",
|
|
91
|
+
hourCycle: "h23",
|
|
92
|
+
timeZone: "UTC",
|
|
93
|
+
}).format(new Date(Date.UTC(2000, 0, 1, hour)));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The hour of the day an hour key names. */
|
|
97
|
+
function hourOf(hourKey: string): number {
|
|
98
|
+
return Number(hourKey.slice(11, 13));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What one point of a series is called under the chart and in a hovered bar's label. */
|
|
102
|
+
function pointLabel(series: StatsSeries, at: string, locale: string): string {
|
|
103
|
+
return series.unit === "hour"
|
|
104
|
+
? formatHourLabel(hourOf(at), locale)
|
|
105
|
+
: formatDayLabel(at, locale);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The share of a total one row holds, as a CSS percentage for its bar. */
|
|
109
|
+
function shareOf(views: number, total: number): string {
|
|
110
|
+
if (total <= 0) return "0%";
|
|
111
|
+
return `${Math.round((views / total) * 1000) / 10}%`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The site's own pages by name; any other path as itself. */
|
|
115
|
+
function pathName(path: string, i18n: I18n): string {
|
|
116
|
+
switch (path) {
|
|
117
|
+
case "/":
|
|
118
|
+
return i18n._(
|
|
119
|
+
msg({
|
|
120
|
+
message: "Home",
|
|
121
|
+
comment:
|
|
122
|
+
"@context: Row for the home page in the pages list on the stats page",
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
case "/archive":
|
|
126
|
+
return i18n._(
|
|
127
|
+
msg({
|
|
128
|
+
message: "Archive",
|
|
129
|
+
comment:
|
|
130
|
+
"@context: Row for the archive page in the pages list on the stats page",
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
case "/collections":
|
|
134
|
+
return i18n._(
|
|
135
|
+
msg({
|
|
136
|
+
message: "Collections",
|
|
137
|
+
comment:
|
|
138
|
+
"@context: Row for the collections directory in the pages list on the stats page",
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
141
|
+
case "/featured":
|
|
142
|
+
return i18n._(
|
|
143
|
+
msg({
|
|
144
|
+
message: "Featured",
|
|
145
|
+
comment:
|
|
146
|
+
"@context: Row for the Featured page in the pages list on the stats page",
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
case "/subscribe":
|
|
150
|
+
return i18n._(
|
|
151
|
+
msg({
|
|
152
|
+
message: "Subscribe",
|
|
153
|
+
comment:
|
|
154
|
+
"@context: Row for the subscribe page in the pages list on the stats page",
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
default:
|
|
158
|
+
return path;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* What a page is called on the stats page: a post by the name the rest of
|
|
164
|
+
* Jant gives it, or its address when nothing gives one; a collection by its
|
|
165
|
+
* title; the site's own pages by name; any other path as itself. A deleted
|
|
166
|
+
* post or collection is said to be one.
|
|
167
|
+
*
|
|
168
|
+
* @param page - The page
|
|
169
|
+
* @param i18n - The dashboard's locale
|
|
170
|
+
* @returns The name
|
|
171
|
+
* @example
|
|
172
|
+
* statsPageName({ kind: "path", key: "/" }, i18n); // "Home"
|
|
173
|
+
*/
|
|
174
|
+
export function statsPageName(page: StatsPage, i18n: I18n): string {
|
|
175
|
+
switch (page.kind) {
|
|
176
|
+
case "post":
|
|
177
|
+
if (!page.post) {
|
|
178
|
+
return i18n._(
|
|
179
|
+
msg({
|
|
180
|
+
message: "Deleted post",
|
|
181
|
+
comment:
|
|
182
|
+
"@context: Name on the stats page of a post whose views remain after it was deleted",
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return page.post.title || page.post.slug;
|
|
187
|
+
case "collection":
|
|
188
|
+
if (!page.collection) {
|
|
189
|
+
return i18n._(
|
|
190
|
+
msg({
|
|
191
|
+
message: "Deleted collection",
|
|
192
|
+
comment:
|
|
193
|
+
"@context: Name on the stats page of a collection whose views remain after it was deleted",
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
return page.collection.title;
|
|
198
|
+
case "path":
|
|
199
|
+
return pathName(page.key, i18n);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The public address of a page, while it still has one. */
|
|
204
|
+
function pagePublicPath(page: StatsPage): string | null {
|
|
205
|
+
switch (page.kind) {
|
|
206
|
+
case "post":
|
|
207
|
+
return page.post ? `/${page.post.slug}` : null;
|
|
208
|
+
case "collection":
|
|
209
|
+
return page.collection ? `/${page.collection.slug}` : null;
|
|
210
|
+
case "path":
|
|
211
|
+
return page.key;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* What a referrer is called on the stats page: a host or a tag as itself,
|
|
217
|
+
* the two keys that are not hosts by name.
|
|
218
|
+
*
|
|
219
|
+
* @param key - The referrer's counter key
|
|
220
|
+
* @param i18n - The dashboard's locale
|
|
221
|
+
* @returns The name
|
|
222
|
+
* @example
|
|
223
|
+
* statsReferrerName("", i18n); // "Direct"
|
|
224
|
+
*/
|
|
225
|
+
export function statsReferrerName(key: string, i18n: I18n): string {
|
|
226
|
+
if (key === "") {
|
|
227
|
+
return i18n._(
|
|
228
|
+
msg({
|
|
229
|
+
message: "Direct",
|
|
230
|
+
comment:
|
|
231
|
+
"@context: Name on the stats page of the views with no referrer: typed addresses, apps, feed readers; a row of the referrer list and the heading of their own numbers",
|
|
232
|
+
}),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (key === VIEW_INTERNAL_REFERRER) {
|
|
236
|
+
return i18n._(
|
|
237
|
+
msg({
|
|
238
|
+
message: "Internal",
|
|
239
|
+
comment:
|
|
240
|
+
"@context: Name on the stats page of the views that followed a link from another page of the site; a row of the referrer list and the heading of their own numbers",
|
|
241
|
+
}),
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return key;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** The kind of a page, where the name alone does not say: a post's format, or that it is a collection. */
|
|
248
|
+
function PageBadge({ page }: { page: StatsPage }) {
|
|
249
|
+
const { i18n } = useLingui();
|
|
250
|
+
if (page.kind === "post" && page.post) {
|
|
251
|
+
return <FormatBadge type={page.post.format} />;
|
|
252
|
+
}
|
|
253
|
+
if (page.kind === "collection") {
|
|
254
|
+
return (
|
|
255
|
+
<span class="badge-outline">
|
|
256
|
+
{i18n._(
|
|
257
|
+
msg({
|
|
258
|
+
message: "Collection",
|
|
259
|
+
comment: "@context: Badge on a collection's row on the stats page",
|
|
260
|
+
}),
|
|
261
|
+
)}
|
|
262
|
+
</span>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** The translator the components get from the context; it takes values. */
|
|
269
|
+
type Translator = ReturnType<typeof useLingui>["i18n"];
|
|
270
|
+
|
|
271
|
+
/** What a window is called on the switch. */
|
|
272
|
+
function windowLabel(window: StatsWindow, i18n: Translator): string {
|
|
273
|
+
if (window === 1) {
|
|
274
|
+
return i18n._(
|
|
275
|
+
msg({
|
|
276
|
+
message: "Today",
|
|
277
|
+
comment:
|
|
278
|
+
"@context: The one-day option of the window switch on the stats page",
|
|
279
|
+
}),
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
return i18n._(
|
|
283
|
+
msg({
|
|
284
|
+
message: "{window} days",
|
|
285
|
+
comment:
|
|
286
|
+
"@context: One option of the window switch on the stats page; {window} is 7 or 30",
|
|
287
|
+
}),
|
|
288
|
+
{ window },
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function WindowSwitch({
|
|
293
|
+
days,
|
|
294
|
+
sitePathPrefix,
|
|
295
|
+
target,
|
|
296
|
+
}: {
|
|
297
|
+
days: StatsWindow;
|
|
298
|
+
sitePathPrefix: string;
|
|
299
|
+
target?: StatsTarget;
|
|
300
|
+
}) {
|
|
301
|
+
const { i18n } = useLingui();
|
|
302
|
+
return (
|
|
303
|
+
<nav
|
|
304
|
+
class="settings-stats-windows"
|
|
305
|
+
aria-label={i18n._(
|
|
306
|
+
msg({
|
|
307
|
+
message: "Window",
|
|
308
|
+
comment:
|
|
309
|
+
"@context: Accessible name of the today/7/30-day switch on the stats page",
|
|
310
|
+
}),
|
|
311
|
+
)}
|
|
312
|
+
>
|
|
313
|
+
{STATS_WINDOWS.map((window) => (
|
|
314
|
+
<a
|
|
315
|
+
key={window}
|
|
316
|
+
href={statsHref(sitePathPrefix, window, target)}
|
|
317
|
+
class="settings-stats-window"
|
|
318
|
+
aria-current={window === days ? "page" : undefined}
|
|
319
|
+
>
|
|
320
|
+
{windowLabel(window, i18n)}
|
|
321
|
+
</a>
|
|
322
|
+
))}
|
|
323
|
+
</nav>
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* One slot per point over the whole window, so a bar is the same width
|
|
329
|
+
* whatever the record covers. Today has 24 slots and bars up to the current
|
|
330
|
+
* hour. A longer window has one slot per day; the days before the record
|
|
331
|
+
* have no bar and no baseline, since the baseline starts where counting did.
|
|
332
|
+
* The total line has then already named that day, so the axis carries
|
|
333
|
+
* today's date alone; it names both ends only when every day was counted.
|
|
334
|
+
* A slot names its point and count in `data-label`, which the stylesheet
|
|
335
|
+
* shows above the bar while the slot is hovered: the whole column answers,
|
|
336
|
+
* so a short bar is as easy to read as a tall one.
|
|
337
|
+
*/
|
|
338
|
+
function ViewsChart({
|
|
339
|
+
series,
|
|
340
|
+
start,
|
|
341
|
+
locale,
|
|
342
|
+
}: {
|
|
343
|
+
series: StatsSeries;
|
|
344
|
+
start: string | null;
|
|
345
|
+
locale: string;
|
|
346
|
+
}) {
|
|
347
|
+
const { i18n } = useLingui();
|
|
348
|
+
const { unit, points } = series;
|
|
349
|
+
const slots = unit === "hour" ? 24 : points.length;
|
|
350
|
+
const peak = Math.max(1, ...points.map((point) => point.views));
|
|
351
|
+
const startIndex =
|
|
352
|
+
unit === "day" && start
|
|
353
|
+
? Math.max(
|
|
354
|
+
0,
|
|
355
|
+
points.findIndex((point) => point.at === start),
|
|
356
|
+
)
|
|
357
|
+
: 0;
|
|
358
|
+
const single = unit === "day" && start !== null;
|
|
359
|
+
const firstLabel =
|
|
360
|
+
unit === "hour"
|
|
361
|
+
? formatHourLabel(0, locale)
|
|
362
|
+
: points[startIndex] && formatDayLabel(points[startIndex].at, locale);
|
|
363
|
+
const last = points.at(-1);
|
|
364
|
+
const lastLabel =
|
|
365
|
+
unit === "hour"
|
|
366
|
+
? formatHourLabel(23, locale)
|
|
367
|
+
: last && formatDayLabel(last.at, locale);
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<figure class="settings-stats-figure">
|
|
371
|
+
<div
|
|
372
|
+
class="settings-stats-chart"
|
|
373
|
+
role="img"
|
|
374
|
+
aria-label={
|
|
375
|
+
unit === "hour"
|
|
376
|
+
? i18n._(
|
|
377
|
+
msg({
|
|
378
|
+
message: "Views per hour",
|
|
379
|
+
comment:
|
|
380
|
+
"@context: Accessible name of today's bar chart on the stats page",
|
|
381
|
+
}),
|
|
382
|
+
)
|
|
383
|
+
: i18n._(
|
|
384
|
+
msg({
|
|
385
|
+
message: "Views per day",
|
|
386
|
+
comment:
|
|
387
|
+
"@context: Accessible name of the bar chart on the stats page",
|
|
388
|
+
}),
|
|
389
|
+
)
|
|
390
|
+
}
|
|
391
|
+
>
|
|
392
|
+
{Array.from({ length: slots }, (_, index) => {
|
|
393
|
+
const point = points[index];
|
|
394
|
+
if (!point || index < startIndex) {
|
|
395
|
+
return <span key={`slot-${index}`} class="settings-stats-slot" />;
|
|
396
|
+
}
|
|
397
|
+
const height = (point.views / peak) * 100;
|
|
398
|
+
return (
|
|
399
|
+
<span
|
|
400
|
+
key={point.at}
|
|
401
|
+
class="settings-stats-slot"
|
|
402
|
+
style={`--stats-height:${height}%`}
|
|
403
|
+
data-label={i18n._(
|
|
404
|
+
msg({
|
|
405
|
+
message:
|
|
406
|
+
"{day}: {count, plural, one {# view} other {# views}}",
|
|
407
|
+
comment:
|
|
408
|
+
"@context: Tooltip on one bar of the stats chart; {day} is a date like Nov 8 or an hour like 14:00",
|
|
409
|
+
}),
|
|
410
|
+
{
|
|
411
|
+
day: pointLabel(series, point.at, locale),
|
|
412
|
+
count: point.views,
|
|
413
|
+
},
|
|
414
|
+
)}
|
|
415
|
+
>
|
|
416
|
+
<span class="settings-stats-bar" />
|
|
417
|
+
</span>
|
|
418
|
+
);
|
|
419
|
+
})}
|
|
420
|
+
</div>
|
|
421
|
+
{firstLabel && lastLabel && (
|
|
422
|
+
<figcaption
|
|
423
|
+
class={`settings-stats-axis${single ? " settings-stats-axis-single" : ""}`}
|
|
424
|
+
style={`--stats-start:${(startIndex / slots) * 100}%`}
|
|
425
|
+
aria-hidden="true"
|
|
426
|
+
>
|
|
427
|
+
{!single && <span>{firstLabel}</span>}
|
|
428
|
+
<span>{lastLabel}</span>
|
|
429
|
+
</figcaption>
|
|
430
|
+
)}
|
|
431
|
+
</figure>
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** One ranked row: its place, its name, its kind, its count, and a bar for its share. */
|
|
436
|
+
function RankedRow({
|
|
437
|
+
rank,
|
|
438
|
+
share,
|
|
439
|
+
views,
|
|
440
|
+
children,
|
|
441
|
+
}: {
|
|
442
|
+
rank: number;
|
|
443
|
+
share: string;
|
|
444
|
+
views: number;
|
|
445
|
+
children: unknown;
|
|
446
|
+
}) {
|
|
447
|
+
return (
|
|
448
|
+
<li class="settings-stats-row" style={`--stats-share:${share}`}>
|
|
449
|
+
<span class="settings-stats-rank">{rank}</span>
|
|
450
|
+
{children}
|
|
451
|
+
<span class="settings-stats-count">{views}</span>
|
|
452
|
+
</li>
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Where the views came from, each referrer a link to the pages it sent
|
|
458
|
+
* readers to. Internal and Direct take their place among the hosts by
|
|
459
|
+
* size; Other is last and opens nothing, being a remainder.
|
|
460
|
+
*/
|
|
461
|
+
function ReferrerList({
|
|
462
|
+
referrers,
|
|
463
|
+
total,
|
|
464
|
+
days,
|
|
465
|
+
sitePathPrefix,
|
|
466
|
+
}: {
|
|
467
|
+
referrers: StatsReferrers;
|
|
468
|
+
total: number;
|
|
469
|
+
days: StatsWindow;
|
|
470
|
+
sitePathPrefix: string;
|
|
471
|
+
}) {
|
|
472
|
+
const { i18n } = useLingui();
|
|
473
|
+
const rows: { key: string | null; label: string; views: number }[] = [
|
|
474
|
+
...referrers.top.map((row) => ({
|
|
475
|
+
key: row.host,
|
|
476
|
+
label: row.host,
|
|
477
|
+
views: row.views,
|
|
478
|
+
})),
|
|
479
|
+
{
|
|
480
|
+
key: VIEW_INTERNAL_REFERRER,
|
|
481
|
+
label: statsReferrerName(VIEW_INTERNAL_REFERRER, i18n),
|
|
482
|
+
views: referrers.internal,
|
|
483
|
+
},
|
|
484
|
+
{ key: "", label: statsReferrerName("", i18n), views: referrers.direct },
|
|
485
|
+
]
|
|
486
|
+
.filter((row) => row.views > 0)
|
|
487
|
+
.sort((a, b) => b.views - a.views);
|
|
488
|
+
if (referrers.other > 0) {
|
|
489
|
+
rows.push({
|
|
490
|
+
key: null,
|
|
491
|
+
label: i18n._(
|
|
492
|
+
msg({
|
|
493
|
+
message: "Other",
|
|
494
|
+
comment:
|
|
495
|
+
"@context: Row on the stats page for every referrer past the ten listed",
|
|
496
|
+
}),
|
|
497
|
+
),
|
|
498
|
+
views: referrers.other,
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return (
|
|
503
|
+
<section class="settings-stats-section">
|
|
504
|
+
<h2 class="settings-stats-heading">
|
|
505
|
+
{i18n._(
|
|
506
|
+
msg({
|
|
507
|
+
message: "Referrers",
|
|
508
|
+
comment: "@context: Heading of the referrer list on the stats page",
|
|
509
|
+
}),
|
|
510
|
+
)}
|
|
511
|
+
</h2>
|
|
512
|
+
<ol class="settings-stats-list">
|
|
513
|
+
{rows.map((row, index) => (
|
|
514
|
+
<RankedRow
|
|
515
|
+
key={row.label}
|
|
516
|
+
rank={index + 1}
|
|
517
|
+
share={shareOf(row.views, total)}
|
|
518
|
+
views={row.views}
|
|
519
|
+
>
|
|
520
|
+
{row.key === null ? (
|
|
521
|
+
<span class="settings-stats-label">{row.label}</span>
|
|
522
|
+
) : (
|
|
523
|
+
<a
|
|
524
|
+
href={statsHref(sitePathPrefix, days, { referrer: row.key })}
|
|
525
|
+
class="settings-stats-label settings-stats-link"
|
|
526
|
+
>
|
|
527
|
+
{row.label}
|
|
528
|
+
</a>
|
|
529
|
+
)}
|
|
530
|
+
</RankedRow>
|
|
531
|
+
))}
|
|
532
|
+
</ol>
|
|
533
|
+
</section>
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** The most-viewed pages of the window, each a link to its own numbers. */
|
|
538
|
+
function PageList({
|
|
539
|
+
pages,
|
|
540
|
+
total,
|
|
541
|
+
days,
|
|
542
|
+
sitePathPrefix,
|
|
543
|
+
}: {
|
|
544
|
+
pages: StatsPageRow[];
|
|
545
|
+
total: number;
|
|
546
|
+
days: StatsWindow;
|
|
547
|
+
sitePathPrefix: string;
|
|
548
|
+
}) {
|
|
549
|
+
const { i18n } = useLingui();
|
|
550
|
+
|
|
551
|
+
return (
|
|
552
|
+
<section class="settings-stats-section">
|
|
553
|
+
<h2 class="settings-stats-heading">
|
|
554
|
+
{i18n._(
|
|
555
|
+
msg({
|
|
556
|
+
message: "Pages",
|
|
557
|
+
comment:
|
|
558
|
+
"@context: Heading of the most-viewed pages on the stats page",
|
|
559
|
+
}),
|
|
560
|
+
)}
|
|
561
|
+
</h2>
|
|
562
|
+
<ol class="settings-stats-list">
|
|
563
|
+
{pages.map((row, index) => (
|
|
564
|
+
<RankedRow
|
|
565
|
+
key={row.key}
|
|
566
|
+
rank={index + 1}
|
|
567
|
+
share={shareOf(row.views, total)}
|
|
568
|
+
views={row.views}
|
|
569
|
+
>
|
|
570
|
+
<a
|
|
571
|
+
href={statsHref(sitePathPrefix, days, { page: row.key })}
|
|
572
|
+
class="settings-stats-label settings-stats-link"
|
|
573
|
+
>
|
|
574
|
+
{statsPageName(row, i18n)}
|
|
575
|
+
</a>
|
|
576
|
+
<PageBadge page={row} />
|
|
577
|
+
</RankedRow>
|
|
578
|
+
))}
|
|
579
|
+
</ol>
|
|
580
|
+
</section>
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function Toggle({
|
|
585
|
+
enabled,
|
|
586
|
+
sitePathPrefix,
|
|
587
|
+
demoMode,
|
|
588
|
+
}: {
|
|
589
|
+
enabled: boolean;
|
|
590
|
+
sitePathPrefix: string;
|
|
591
|
+
demoMode: boolean;
|
|
592
|
+
}) {
|
|
593
|
+
const { i18n } = useLingui();
|
|
594
|
+
const endpoint = toPublicPath("/settings/stats", sitePathPrefix);
|
|
595
|
+
const confirmOptions = JSON.stringify({
|
|
596
|
+
message: i18n._(
|
|
597
|
+
msg({
|
|
598
|
+
message: "Turn off stats and delete every count? This can't be undone.",
|
|
599
|
+
comment:
|
|
600
|
+
"@context: Confirmation before turning off stats, which deletes the counts",
|
|
601
|
+
}),
|
|
602
|
+
),
|
|
603
|
+
confirmLabel: i18n._(
|
|
604
|
+
msg({
|
|
605
|
+
message: "Turn Off",
|
|
606
|
+
comment: "@context: Confirm button for turning off stats",
|
|
607
|
+
}),
|
|
608
|
+
),
|
|
609
|
+
cancelLabel: i18n._(
|
|
610
|
+
msg({
|
|
611
|
+
message: "Cancel",
|
|
612
|
+
comment: "@context: Cancel button in the confirm dialog",
|
|
613
|
+
}),
|
|
614
|
+
),
|
|
615
|
+
tone: "danger",
|
|
616
|
+
});
|
|
617
|
+
// Turning on saves at once. Turning off asks first, since it deletes; a
|
|
618
|
+
// cancelled dialog puts the box back.
|
|
619
|
+
const onChange = `(async () => { if ($enabled) { @post('${endpoint}'); return; } if (await jantConfirm(${confirmOptions})) { @post('${endpoint}') } else { $enabled = true } })()`;
|
|
620
|
+
|
|
621
|
+
return (
|
|
622
|
+
<section
|
|
623
|
+
class="settings-stats-section"
|
|
624
|
+
data-signals={JSON.stringify({ enabled })}
|
|
625
|
+
>
|
|
626
|
+
<label class="flex items-center gap-2 cursor-pointer">
|
|
627
|
+
<input
|
|
628
|
+
type="checkbox"
|
|
629
|
+
class="checkbox"
|
|
630
|
+
checked={enabled}
|
|
631
|
+
disabled={demoMode}
|
|
632
|
+
data-bind="enabled"
|
|
633
|
+
data-on:change={onChange}
|
|
634
|
+
/>
|
|
635
|
+
<span>
|
|
636
|
+
{i18n._(
|
|
637
|
+
msg({
|
|
638
|
+
message: "Count page views",
|
|
639
|
+
comment: "@context: Checkbox label on the stats page",
|
|
640
|
+
}),
|
|
641
|
+
)}
|
|
642
|
+
</span>
|
|
643
|
+
</label>
|
|
644
|
+
<p class="text-sm text-muted-foreground">
|
|
645
|
+
{demoMode
|
|
646
|
+
? i18n._(
|
|
647
|
+
msg({
|
|
648
|
+
message: "Stats settings are locked in demo mode.",
|
|
649
|
+
comment:
|
|
650
|
+
"@context: Note under the stats checkbox when demo restrictions apply",
|
|
651
|
+
}),
|
|
652
|
+
)
|
|
653
|
+
: i18n._(
|
|
654
|
+
msg({
|
|
655
|
+
message:
|
|
656
|
+
"Counts are kept for {days} days and store nothing about any reader. Turning this off deletes them.",
|
|
657
|
+
comment:
|
|
658
|
+
"@context: Help text under the stats checkbox; {days} is the retention window",
|
|
659
|
+
}),
|
|
660
|
+
{ days: VIEW_COUNT_RETENTION_DAYS },
|
|
661
|
+
)}
|
|
662
|
+
</p>
|
|
663
|
+
</section>
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* The total line. Today says so. While the record began inside a longer
|
|
669
|
+
* window it names the day, since "the last 30 days" would claim days that
|
|
670
|
+
* were never counted.
|
|
671
|
+
*/
|
|
672
|
+
function TotalLine({
|
|
673
|
+
shown,
|
|
674
|
+
locale,
|
|
675
|
+
}: {
|
|
676
|
+
shown: Pick<StatsOverview, "days" | "total" | "start">;
|
|
677
|
+
locale: string;
|
|
678
|
+
}) {
|
|
679
|
+
const { i18n } = useLingui();
|
|
680
|
+
if (shown.days === 1) {
|
|
681
|
+
return (
|
|
682
|
+
<p class="settings-stats-total">
|
|
683
|
+
{i18n._(
|
|
684
|
+
msg({
|
|
685
|
+
message: "{count, plural, one {# view} other {# views}} today",
|
|
686
|
+
comment: "@context: Total line on the stats page for today",
|
|
687
|
+
}),
|
|
688
|
+
{ count: shown.total },
|
|
689
|
+
)}
|
|
690
|
+
</p>
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
return (
|
|
694
|
+
<p class="settings-stats-total">
|
|
695
|
+
{shown.start
|
|
696
|
+
? i18n._(
|
|
697
|
+
msg({
|
|
698
|
+
message:
|
|
699
|
+
"{count, plural, one {# view} other {# views}} since {date}",
|
|
700
|
+
comment:
|
|
701
|
+
"@context: Total line on the stats page while counting began inside the window; {date} is a day like Nov 9",
|
|
702
|
+
}),
|
|
703
|
+
{ count: shown.total, date: formatDayLabel(shown.start, locale) },
|
|
704
|
+
)
|
|
705
|
+
: i18n._(
|
|
706
|
+
msg({
|
|
707
|
+
message:
|
|
708
|
+
"{count, plural, one {# view} other {# views}} in the last {days} days",
|
|
709
|
+
comment:
|
|
710
|
+
"@context: Total line on the stats page; {days} is 7 or 30",
|
|
711
|
+
}),
|
|
712
|
+
{ count: shown.total, days: shown.days },
|
|
713
|
+
)}
|
|
714
|
+
</p>
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/** The heading of one page's numbers: its name, linked to it while it exists, and its kind. */
|
|
719
|
+
function PageHeading({
|
|
720
|
+
page,
|
|
721
|
+
sitePathPrefix,
|
|
722
|
+
}: {
|
|
723
|
+
page: StatsPage;
|
|
724
|
+
sitePathPrefix: string;
|
|
725
|
+
}) {
|
|
726
|
+
const { i18n } = useLingui();
|
|
727
|
+
const name = statsPageName(page, i18n);
|
|
728
|
+
const path = pagePublicPath(page);
|
|
729
|
+
return (
|
|
730
|
+
<h1 class="settings-stats-title">
|
|
731
|
+
{path ? (
|
|
732
|
+
<a
|
|
733
|
+
href={toPublicPath(path, sitePathPrefix)}
|
|
734
|
+
class="settings-stats-title-name settings-stats-link"
|
|
735
|
+
>
|
|
736
|
+
{name}
|
|
737
|
+
</a>
|
|
738
|
+
) : (
|
|
739
|
+
<span class="settings-stats-title-name">{name}</span>
|
|
740
|
+
)}
|
|
741
|
+
<PageBadge page={page} />
|
|
742
|
+
</h1>
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/** The heading of one referrer's numbers: its name, as the list wrote it. */
|
|
747
|
+
function ReferrerHeading({ referrer }: { referrer: string }) {
|
|
748
|
+
const { i18n } = useLingui();
|
|
749
|
+
return (
|
|
750
|
+
<h1 class="settings-stats-title">
|
|
751
|
+
<span class="settings-stats-title-name">
|
|
752
|
+
{statsReferrerName(referrer, i18n)}
|
|
753
|
+
</span>
|
|
754
|
+
</h1>
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
export function StatsContent({
|
|
759
|
+
enabled,
|
|
760
|
+
days,
|
|
761
|
+
overview,
|
|
762
|
+
page,
|
|
763
|
+
referrer,
|
|
764
|
+
sitePathPrefix,
|
|
765
|
+
demoMode,
|
|
766
|
+
}: StatsContentProps) {
|
|
767
|
+
const { i18n } = useLingui();
|
|
768
|
+
const locale = i18n.locale;
|
|
769
|
+
const shown = page ?? referrer ?? overview;
|
|
770
|
+
// The site and a referrer list pages; the site and a page list referrers.
|
|
771
|
+
const pages = overview?.pages ?? referrer?.pages ?? null;
|
|
772
|
+
const referrers = overview?.referrers ?? page?.referrers ?? null;
|
|
773
|
+
const target: StatsTarget | undefined = page
|
|
774
|
+
? { page: page.page.key }
|
|
775
|
+
: referrer
|
|
776
|
+
? { referrer: referrer.referrer }
|
|
777
|
+
: undefined;
|
|
778
|
+
|
|
779
|
+
return (
|
|
780
|
+
<div class="settings-stats">
|
|
781
|
+
<header class="settings-stats-header">
|
|
782
|
+
{page ? (
|
|
783
|
+
<PageHeading page={page.page} sitePathPrefix={sitePathPrefix} />
|
|
784
|
+
) : referrer ? (
|
|
785
|
+
<ReferrerHeading referrer={referrer.referrer} />
|
|
786
|
+
) : (
|
|
787
|
+
<h1 class="settings-stats-title">
|
|
788
|
+
{i18n._(
|
|
789
|
+
msg({
|
|
790
|
+
message: "Stats",
|
|
791
|
+
comment: "@context: Stats page title",
|
|
792
|
+
}),
|
|
793
|
+
)}
|
|
794
|
+
</h1>
|
|
795
|
+
)}
|
|
796
|
+
{enabled && (
|
|
797
|
+
<WindowSwitch
|
|
798
|
+
days={days}
|
|
799
|
+
sitePathPrefix={sitePathPrefix}
|
|
800
|
+
target={target}
|
|
801
|
+
/>
|
|
802
|
+
)}
|
|
803
|
+
</header>
|
|
804
|
+
|
|
805
|
+
{!enabled ? (
|
|
806
|
+
<p class="text-sm text-muted-foreground">
|
|
807
|
+
{i18n._(
|
|
808
|
+
msg({
|
|
809
|
+
message: "Stats are off. Turn them on below to start counting.",
|
|
810
|
+
comment: "@context: Stats page body when counting is turned off",
|
|
811
|
+
}),
|
|
812
|
+
)}
|
|
813
|
+
</p>
|
|
814
|
+
) : (
|
|
815
|
+
shown && (
|
|
816
|
+
<>
|
|
817
|
+
<TotalLine shown={shown} locale={locale} />
|
|
818
|
+
{shown.series && (
|
|
819
|
+
<ViewsChart
|
|
820
|
+
series={shown.series}
|
|
821
|
+
start={shown.start}
|
|
822
|
+
locale={locale}
|
|
823
|
+
/>
|
|
824
|
+
)}
|
|
825
|
+
{/* The total line has already said there is nothing to list. */}
|
|
826
|
+
{shown.total > 0 && pages && (
|
|
827
|
+
<PageList
|
|
828
|
+
pages={pages}
|
|
829
|
+
total={shown.total}
|
|
830
|
+
days={days}
|
|
831
|
+
sitePathPrefix={sitePathPrefix}
|
|
832
|
+
/>
|
|
833
|
+
)}
|
|
834
|
+
{shown.total > 0 && referrers && (
|
|
835
|
+
<ReferrerList
|
|
836
|
+
referrers={referrers}
|
|
837
|
+
total={shown.total}
|
|
838
|
+
days={days}
|
|
839
|
+
sitePathPrefix={sitePathPrefix}
|
|
840
|
+
/>
|
|
841
|
+
)}
|
|
842
|
+
</>
|
|
843
|
+
)
|
|
844
|
+
)}
|
|
845
|
+
|
|
846
|
+
{!target && (
|
|
847
|
+
<Toggle
|
|
848
|
+
enabled={enabled}
|
|
849
|
+
sitePathPrefix={sitePathPrefix}
|
|
850
|
+
demoMode={demoMode}
|
|
851
|
+
/>
|
|
852
|
+
)}
|
|
853
|
+
</div>
|
|
854
|
+
);
|
|
855
|
+
}
|