mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Handle domain name in share URL path
Skip domain-like segments (containing dots) when parsing the share path.
e.g., /share/slug/aol.com is treated as /share/slug
/share/slug/aol.com/events is treated as /share/slug/events
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c9e14f3bce
commit
4e8be724ac
2 changed files with 26 additions and 2 deletions
|
|
@ -32,11 +32,23 @@ const ALL_SECTION_IDS = [
|
||||||
'attribution',
|
'attribution',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function getSharePath(pathname: string) {
|
||||||
|
const segments = pathname.split('/');
|
||||||
|
const firstSegment = segments[3];
|
||||||
|
|
||||||
|
// If first segment looks like a domain name, skip it
|
||||||
|
if (firstSegment?.includes('.')) {
|
||||||
|
return segments[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
return firstSegment;
|
||||||
|
}
|
||||||
|
|
||||||
export function ShareProvider({ slug, children }: { slug: string; children: ReactNode }) {
|
export function ShareProvider({ slug, children }: { slug: string; children: ReactNode }) {
|
||||||
const { share, isLoading, isFetching } = useShareTokenQuery(slug);
|
const { share, isLoading, isFetching } = useShareTokenQuery(slug);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const path = pathname.split('/')[3];
|
const path = getSharePath(pathname);
|
||||||
|
|
||||||
const allowedSections = share?.parameters
|
const allowedSections = share?.parameters
|
||||||
? ALL_SECTION_IDS.filter(id => share.parameters[id] !== false)
|
? ALL_SECTION_IDS.filter(id => share.parameters[id] !== false)
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,23 @@ const PAGE_COMPONENTS: Record<string, React.ComponentType<{ websiteId: string }>
|
||||||
attribution: AttributionPage,
|
attribution: AttributionPage,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getSharePath(pathname: string) {
|
||||||
|
const segments = pathname.split('/');
|
||||||
|
const firstSegment = segments[3];
|
||||||
|
|
||||||
|
// If first segment looks like a domain name, skip it
|
||||||
|
if (firstSegment?.includes('.')) {
|
||||||
|
return segments[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
return firstSegment;
|
||||||
|
}
|
||||||
|
|
||||||
export function SharePage() {
|
export function SharePage() {
|
||||||
const share = useShare();
|
const share = useShare();
|
||||||
const { setTheme } = useTheme();
|
const { setTheme } = useTheme();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const path = pathname.split('/')[3];
|
const path = getSharePath(pathname);
|
||||||
const { websiteId, parameters = {} } = share;
|
const { websiteId, parameters = {} } = share;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue