@redneckz/wildless-cms-uni-blocks 0.8.5 → 0.8.7
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/bundle/bundle.umd.js +38 -43
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/Footer/Sitemap.d.ts +0 -2
- package/bundle/components/Header/Header.fallback.d.ts +1 -2
- package/bundle/hooks/useLink.d.ts +6 -5
- package/bundle/services/sitemap/fallbackWCMSResource.d.ts +2 -0
- package/bundle/services/sitemap/isHrefActive.d.ts +4 -2
- package/bundle/services/sitemap/useSWRResource.d.ts +1 -1
- package/bundle/utils/url.d.ts +1 -3
- package/dist/components/Footer/Footer.fallback.js +3 -6
- package/dist/components/Footer/Footer.fallback.js.map +1 -1
- package/dist/components/Footer/Sitemap.d.ts +0 -2
- package/dist/components/Footer/Sitemap.js +2 -4
- package/dist/components/Footer/Sitemap.js.map +1 -1
- package/dist/components/Header/Header.fallback.d.ts +1 -2
- package/dist/components/Header/Header.fallback.js +2 -7
- package/dist/components/Header/Header.fallback.js.map +1 -1
- package/dist/hooks/useLink.d.ts +6 -5
- package/dist/hooks/useLink.js +26 -18
- package/dist/hooks/useLink.js.map +1 -1
- package/dist/services/BlockRouter/BlockRouter.js +1 -1
- package/dist/services/BlockRouter/BlockRouter.js.map +1 -1
- package/dist/services/sitemap/fallbackWCMSResource.d.ts +2 -0
- package/dist/services/sitemap/fallbackWCMSResource.js +8 -0
- package/dist/services/sitemap/fallbackWCMSResource.js.map +1 -0
- package/dist/services/sitemap/isHrefActive.d.ts +4 -2
- package/dist/services/sitemap/isHrefActive.js +1 -6
- package/dist/services/sitemap/isHrefActive.js.map +1 -1
- package/dist/services/sitemap/isTopItemActive.js +4 -1
- package/dist/services/sitemap/isTopItemActive.js.map +1 -1
- package/dist/services/sitemap/useSWRResource.d.ts +1 -1
- package/dist/services/sitemap/useSWRResource.js +2 -2
- package/dist/setup-fixture.js +3 -1
- package/dist/setup-fixture.js.map +1 -1
- package/dist/utils/url.d.ts +1 -3
- package/dist/utils/url.js +4 -8
- package/dist/utils/url.js.map +1 -1
- package/lib/components/Footer/Footer.fallback.js +1 -4
- package/lib/components/Footer/Footer.fallback.js.map +1 -1
- package/lib/components/Footer/Sitemap.d.ts +0 -2
- package/lib/components/Footer/Sitemap.js +2 -4
- package/lib/components/Footer/Sitemap.js.map +1 -1
- package/lib/components/Header/Header.fallback.d.ts +1 -2
- package/lib/components/Header/Header.fallback.js +2 -7
- package/lib/components/Header/Header.fallback.js.map +1 -1
- package/lib/hooks/useLink.d.ts +6 -5
- package/lib/hooks/useLink.js +27 -19
- package/lib/hooks/useLink.js.map +1 -1
- package/lib/services/BlockRouter/BlockRouter.js +1 -1
- package/lib/services/BlockRouter/BlockRouter.js.map +1 -1
- package/lib/services/sitemap/fallbackWCMSResource.d.ts +2 -0
- package/lib/services/sitemap/fallbackWCMSResource.js +5 -0
- package/lib/services/sitemap/fallbackWCMSResource.js.map +1 -0
- package/lib/services/sitemap/isHrefActive.d.ts +4 -2
- package/lib/services/sitemap/isHrefActive.js +1 -6
- package/lib/services/sitemap/isHrefActive.js.map +1 -1
- package/lib/services/sitemap/isTopItemActive.js +4 -1
- package/lib/services/sitemap/isTopItemActive.js.map +1 -1
- package/lib/services/sitemap/useSWRResource.d.ts +1 -1
- package/lib/services/sitemap/useSWRResource.js +2 -2
- package/lib/setup-fixture.js +3 -1
- package/lib/setup-fixture.js.map +1 -1
- package/lib/utils/url.d.ts +1 -3
- package/lib/utils/url.js +2 -4
- package/lib/utils/url.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +36 -35
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/Footer/Sitemap.d.ts +0 -2
- package/mobile/bundle/components/Header/Header.fallback.d.ts +1 -2
- package/mobile/bundle/hooks/useLink.d.ts +6 -5
- package/mobile/bundle/services/sitemap/fallbackWCMSResource.d.ts +2 -0
- package/mobile/bundle/services/sitemap/isHrefActive.d.ts +4 -2
- package/mobile/bundle/services/sitemap/useSWRResource.d.ts +1 -1
- package/mobile/bundle/utils/url.d.ts +1 -3
- package/mobile/dist/components/Footer/Footer.fallback.js +3 -6
- package/mobile/dist/components/Footer/Footer.fallback.js.map +1 -1
- package/mobile/dist/components/Footer/Sitemap.d.ts +0 -2
- package/mobile/dist/components/Footer/Sitemap.js +2 -4
- package/mobile/dist/components/Footer/Sitemap.js.map +1 -1
- package/mobile/dist/components/Header/Header.fallback.d.ts +1 -2
- package/mobile/dist/components/Header/Header.fallback.js +2 -7
- package/mobile/dist/components/Header/Header.fallback.js.map +1 -1
- package/mobile/dist/hooks/useLink.d.ts +6 -5
- package/mobile/dist/hooks/useLink.js +26 -18
- package/mobile/dist/hooks/useLink.js.map +1 -1
- package/mobile/dist/services/BlockRouter/BlockRouter.js +1 -1
- package/mobile/dist/services/BlockRouter/BlockRouter.js.map +1 -1
- package/mobile/dist/services/sitemap/fallbackWCMSResource.d.ts +2 -0
- package/mobile/dist/services/sitemap/fallbackWCMSResource.js +8 -0
- package/mobile/dist/services/sitemap/fallbackWCMSResource.js.map +1 -0
- package/mobile/dist/services/sitemap/isHrefActive.d.ts +4 -2
- package/mobile/dist/services/sitemap/isHrefActive.js +1 -6
- package/mobile/dist/services/sitemap/isHrefActive.js.map +1 -1
- package/mobile/dist/services/sitemap/isTopItemActive.js +4 -1
- package/mobile/dist/services/sitemap/isTopItemActive.js.map +1 -1
- package/mobile/dist/services/sitemap/useSWRResource.d.ts +1 -1
- package/mobile/dist/services/sitemap/useSWRResource.js +2 -2
- package/mobile/dist/setup-fixture.js +3 -1
- package/mobile/dist/setup-fixture.js.map +1 -1
- package/mobile/dist/utils/url.d.ts +1 -3
- package/mobile/dist/utils/url.js +4 -8
- package/mobile/dist/utils/url.js.map +1 -1
- package/mobile/lib/components/Footer/Footer.fallback.js +1 -4
- package/mobile/lib/components/Footer/Footer.fallback.js.map +1 -1
- package/mobile/lib/components/Footer/Sitemap.d.ts +0 -2
- package/mobile/lib/components/Footer/Sitemap.js +2 -4
- package/mobile/lib/components/Footer/Sitemap.js.map +1 -1
- package/mobile/lib/components/Header/Header.fallback.d.ts +1 -2
- package/mobile/lib/components/Header/Header.fallback.js +2 -7
- package/mobile/lib/components/Header/Header.fallback.js.map +1 -1
- package/mobile/lib/hooks/useLink.d.ts +6 -5
- package/mobile/lib/hooks/useLink.js +27 -19
- package/mobile/lib/hooks/useLink.js.map +1 -1
- package/mobile/lib/services/BlockRouter/BlockRouter.js +1 -1
- package/mobile/lib/services/BlockRouter/BlockRouter.js.map +1 -1
- package/mobile/lib/services/sitemap/fallbackWCMSResource.d.ts +2 -0
- package/mobile/lib/services/sitemap/fallbackWCMSResource.js +5 -0
- package/mobile/lib/services/sitemap/fallbackWCMSResource.js.map +1 -0
- package/mobile/lib/services/sitemap/isHrefActive.d.ts +4 -2
- package/mobile/lib/services/sitemap/isHrefActive.js +1 -6
- package/mobile/lib/services/sitemap/isHrefActive.js.map +1 -1
- package/mobile/lib/services/sitemap/isTopItemActive.js +4 -1
- package/mobile/lib/services/sitemap/isTopItemActive.js.map +1 -1
- package/mobile/lib/services/sitemap/useSWRResource.d.ts +1 -1
- package/mobile/lib/services/sitemap/useSWRResource.js +2 -2
- package/mobile/lib/setup-fixture.js +3 -1
- package/mobile/lib/setup-fixture.js.map +1 -1
- package/mobile/lib/utils/url.d.ts +1 -3
- package/mobile/lib/utils/url.js +2 -4
- package/mobile/lib/utils/url.js.map +1 -1
- package/mobile/src/components/Footer/Footer.fallback.ts +1 -6
- package/mobile/src/components/Footer/Sitemap.tsx +2 -6
- package/mobile/src/components/Header/Header.fallback.ts +2 -12
- package/mobile/src/hooks/useLink.ts +31 -20
- package/mobile/src/services/BlockRouter/BlockRouter.ts +1 -1
- package/mobile/src/services/sitemap/fallbackWCMSResource.ts +7 -0
- package/mobile/src/services/sitemap/isHrefActive.ts +3 -12
- package/mobile/src/services/sitemap/isTopItemActive.ts +4 -1
- package/mobile/src/services/sitemap/useSWRResource.ts +2 -2
- package/mobile/src/setup-fixture.ts +3 -1
- package/mobile/src/utils/url.ts +4 -4
- package/package.json +1 -1
- package/src/components/Footer/Footer.fallback.ts +1 -6
- package/src/components/Footer/Sitemap.tsx +2 -6
- package/src/components/Header/Header.fallback.ts +2 -12
- package/src/hooks/useLink.ts +31 -20
- package/src/services/BlockRouter/BlockRouter.ts +1 -1
- package/src/services/sitemap/fallbackWCMSResource.ts +7 -0
- package/src/services/sitemap/isHrefActive.ts +3 -12
- package/src/services/sitemap/isTopItemActive.ts +4 -1
- package/src/services/sitemap/useSWRResource.ts +2 -2
- package/src/setup-fixture.ts +3 -1
- package/src/utils/url.ts +4 -4
- package/bundle/services/sitemap/mergeTopItems.d.ts +0 -2
- package/dist/services/sitemap/mergeTopItems.d.ts +0 -2
- package/dist/services/sitemap/mergeTopItems.js +0 -8
- package/dist/services/sitemap/mergeTopItems.js.map +0 -1
- package/lib/services/sitemap/mergeTopItems.d.ts +0 -2
- package/lib/services/sitemap/mergeTopItems.js +0 -5
- package/lib/services/sitemap/mergeTopItems.js.map +0 -1
- package/mobile/bundle/services/sitemap/mergeTopItems.d.ts +0 -2
- package/mobile/dist/services/sitemap/mergeTopItems.d.ts +0 -2
- package/mobile/dist/services/sitemap/mergeTopItems.js +0 -8
- package/mobile/dist/services/sitemap/mergeTopItems.js.map +0 -1
- package/mobile/lib/services/sitemap/mergeTopItems.d.ts +0 -2
- package/mobile/lib/services/sitemap/mergeTopItems.js +0 -5
- package/mobile/lib/services/sitemap/mergeTopItems.js.map +0 -1
- package/mobile/src/services/sitemap/mergeTopItems.ts +0 -12
- package/src/services/sitemap/mergeTopItems.ts +0 -12
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { projectSettings } from '../../ProjectSettings.js';
|
|
1
2
|
import { isHrefActive } from './isHrefActive.js';
|
|
2
|
-
export const isTopItemActive = (router) => (topItem) =>
|
|
3
|
+
export const isTopItemActive = (router) => (topItem) => projectSettings.BASE_PATH
|
|
4
|
+
? isHrefActive({ pathname: projectSettings.BASE_PATH })(topItem)
|
|
5
|
+
: topItem.items?.some(isHrefActive(router)) || isHrefActive(router)(topItem);
|
|
3
6
|
//# sourceMappingURL=isTopItemActive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTopItemActive.js","sourceRoot":"","sources":["../../../src/services/sitemap/isTopItemActive.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,CAAC,MAAM,eAAe,GAC1B,CAAC,MAAc,EAAE,EAAE,CACnB,CAAC,OAAoB,EAAW,EAAE,CAChC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"isTopItemActive.js","sourceRoot":"","sources":["../../../src/services/sitemap/isTopItemActive.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,CAAC,MAAM,eAAe,GAC1B,CAAC,MAAc,EAAE,EAAE,CACnB,CAAC,OAAoB,EAAW,EAAE,CAChC,eAAe,CAAC,SAAS;IACvB,CAAC,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC;IAChE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Fallback } from '../../model/Fallback';
|
|
2
|
-
export declare function useSWRResource<Data>(
|
|
2
|
+
export declare function useSWRResource<Data>(filename: string, fallback?: Fallback): Data;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
2
|
import { fetchJSONUnsafe } from '../../utils/fetchJSON.js';
|
|
3
|
-
export function useSWRResource(
|
|
4
|
-
const { data } = useAsyncData(`/wcms-resources/${
|
|
3
|
+
export function useSWRResource(filename, fallback = {}) {
|
|
4
|
+
const { data } = useAsyncData(`/wcms-resources/${filename}.json`, fetchJSONUnsafe, {
|
|
5
5
|
fallback,
|
|
6
6
|
});
|
|
7
7
|
return data || {};
|
|
@@ -18,7 +18,9 @@ useRouter.setup(() => {
|
|
|
18
18
|
}, []);
|
|
19
19
|
return {
|
|
20
20
|
href,
|
|
21
|
-
pathname:
|
|
21
|
+
pathname: projectSettings.BASE_PATH
|
|
22
|
+
? new URL(href).pathname.substring(projectSettings.BASE_PATH.length - 1)
|
|
23
|
+
: '',
|
|
22
24
|
query: {},
|
|
23
25
|
push: (url) => {
|
|
24
26
|
globalThis.history.pushState(null, '', url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-fixture.js","sourceRoot":"","sources":["../src/setup-fixture.ts"],"names":[],"mappings":"AAAA,OAAO,mCAAmC,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAE3B,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE;IACnB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAC9B,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,eAAe,CAAC,SAAS,cAAc,CACxE,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,mBAAmB,GAAG,GAAG,EAAE;YAC/B,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC,CAAC;QAEF,UAAU,CAAC,gBAAgB,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QAE7D,OAAO,GAAG,EAAE;YACV,UAAU,CAAC,mBAAmB,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QAClE,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"setup-fixture.js","sourceRoot":"","sources":["../src/setup-fixture.ts"],"names":[],"mappings":"AAAA,OAAO,mCAAmC,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAE3B,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE;IACnB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAC9B,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,eAAe,CAAC,SAAS,cAAc,CACxE,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,mBAAmB,GAAG,GAAG,EAAE;YAC/B,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC,CAAC;QAEF,UAAU,CAAC,gBAAgB,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QAE7D,OAAO,GAAG,EAAE;YACV,UAAU,CAAC,mBAAmB,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QAClE,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE,eAAe,CAAC,SAAS;YACjC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,eAAe,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;YACxE,CAAC,CAAC,EAAE;QACN,KAAK,EAAE,EAAE;QACT,IAAI,EAAE,CAAC,GAAW,EAAE,EAAE;YACpB,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,EAAE,CAAC,GAAW,EAAE,EAAE;YACvB,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;QACjD,CAAC;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,gBAAgB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAO,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE;IAC9C,EAAE,CAAC,cAAc,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,CAAC;AACd,CAAC,CAAC,CAAC"}
|
|
@@ -3,6 +3,4 @@ export declare const isURL: (href?: string) => href is `${string}//${string}`;
|
|
|
3
3
|
export declare const isLocalURL: (href: string | undefined, target?: Target) => boolean;
|
|
4
4
|
export declare const isHash: (href?: string) => href is `#${string}`;
|
|
5
5
|
export declare const withoutQuery: (href?: string) => string;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const getPathname: (href?: string) => string | undefined;
|
|
8
|
-
export declare const getHash: (href?: string) => string | undefined;
|
|
6
|
+
export declare const joinPath: (...path: string[]) => string;
|
package/mobile/lib/utils/url.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export const isURL = (href) => Boolean(href?.includes('//'));
|
|
2
2
|
export const isLocalURL = (href, target) => Boolean(href && !isURL(href) && (!target || target === '_self'));
|
|
3
3
|
export const isHash = (href) => Boolean(href?.startsWith('#'));
|
|
4
|
-
export const withoutQuery = (href) => (href || '').replace(
|
|
5
|
-
export const
|
|
6
|
-
export const getPathname = (href) => (isURL(href) ? new URL(href).pathname : undefined);
|
|
7
|
-
export const getHash = (href) => (isURL(href) ? new URL(href).hash : undefined);
|
|
4
|
+
export const withoutQuery = (href) => (href || '').replace(/\?.*/, '').replace(/\/$/, '');
|
|
5
|
+
export const joinPath = (...path) => path.filter(Boolean).join('/').replace(/\/+/g, '/');
|
|
8
6
|
//# sourceMappingURL=url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAa,EAAkC,EAAE,CACrE,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAwB,EAAE,MAAe,EAAE,EAAE,CACtE,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAa,EAAwB,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AAE9F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAa,EAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAa,EAAkC,EAAE,CACrE,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAwB,EAAE,MAAe,EAAE,EAAE,CACtE,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAa,EAAwB,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AAE9F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAa,EAAU,EAAE,CACpD,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAEtD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAc,EAAU,EAAE,CACpD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
1
|
import type { FallbackMap } from '../../model/Fallback';
|
|
3
2
|
import { projectSettings } from '../../ProjectSettings';
|
|
3
|
+
import { fallbackWCMSResource } from '../../services/sitemap/fallbackWCMSResource';
|
|
4
4
|
|
|
5
5
|
export const fallback = (): FallbackMap => ({
|
|
6
6
|
...fallbackWCMSResource(projectSettings.SITEMAP || 'sitemap'),
|
|
7
7
|
...fallbackWCMSResource(projectSettings.FOOTER || 'footer'),
|
|
8
8
|
});
|
|
9
|
-
|
|
10
|
-
const fallbackWCMSResource = (filename: string): FallbackMap => ({
|
|
11
|
-
[filename]: async () =>
|
|
12
|
-
JSON.parse(await readFile(`./content/wcms-resources/${filename}.json`, 'utf-8')),
|
|
13
|
-
});
|
|
@@ -3,25 +3,21 @@ import { useLink } from '../../hooks/useLink';
|
|
|
3
3
|
import type { Fallback } from '../../model/Fallback';
|
|
4
4
|
import type { LinkProps } from '../../model/LinkProps';
|
|
5
5
|
import { projectSettings } from '../../ProjectSettings';
|
|
6
|
-
import { mergeTopItems } from '../../services/sitemap/mergeTopItems';
|
|
7
6
|
import type { SitemapDataProps, TopMenuItem } from '../../services/sitemap/SitemapProps';
|
|
8
7
|
import { useSWRResource } from '../../services/sitemap/useSWRResource';
|
|
9
8
|
|
|
10
9
|
export interface SitemapProps {
|
|
11
10
|
className?: string;
|
|
12
|
-
items?: TopMenuItem[];
|
|
13
11
|
fallback?: Fallback;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
export const Sitemap = JSX<SitemapProps>(({ className = '',
|
|
14
|
+
export const Sitemap = JSX<SitemapProps>(({ className = '', fallback }) => {
|
|
17
15
|
const link = useLink();
|
|
18
|
-
|
|
19
16
|
const sitemap = useSWRResource<SitemapDataProps>(projectSettings.SITEMAP || 'sitemap', fallback);
|
|
20
|
-
const mergedItems = mergeTopItems(sitemap.topItems, items);
|
|
21
17
|
|
|
22
18
|
return (
|
|
23
19
|
<div className={`flex flex-grow items-start justify-between gap-[54px] xl:gap-5 ${className}`}>
|
|
24
|
-
{
|
|
20
|
+
{sitemap.topItems?.map((_, i) => renderColumn(link(_), i))}
|
|
25
21
|
</div>
|
|
26
22
|
);
|
|
27
23
|
});
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
1
|
import { projectSettings } from '../../ProjectSettings';
|
|
3
|
-
import
|
|
2
|
+
import { fallbackWCMSResource } from '../../services/sitemap/fallbackWCMSResource';
|
|
4
3
|
|
|
5
|
-
export const fallback = ()
|
|
6
|
-
[`/wcms-resources/${projectSettings.SITEMAP || 'sitemap'}.json`]: async () => {
|
|
7
|
-
const data = await readFile(
|
|
8
|
-
`./content/wcms-resources/${projectSettings.SITEMAP || 'sitemap'}.json`,
|
|
9
|
-
'utf-8',
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
return JSON.parse(data);
|
|
13
|
-
},
|
|
14
|
-
});
|
|
4
|
+
export const fallback = () => fallbackWCMSResource(projectSettings.SITEMAP || 'sitemap');
|
|
@@ -1,23 +1,43 @@
|
|
|
1
|
-
import type { LinkProps
|
|
1
|
+
import type { LinkProps } from '../model/LinkProps';
|
|
2
|
+
import { projectSettings } from '../ProjectSettings';
|
|
2
3
|
import { useBlockRouter } from '../services/BlockRouter/useBlockRouter';
|
|
3
|
-
import { isHash, isLocalURL } from '../utils/url';
|
|
4
|
+
import { isHash, isLocalURL, joinPath } from '../utils/url';
|
|
4
5
|
import { handlerDecorator } from './handlerDecorator';
|
|
5
6
|
import { useRouter } from './useRouter';
|
|
6
7
|
|
|
7
|
-
interface
|
|
8
|
-
|
|
8
|
+
interface PreventableEvent {
|
|
9
|
+
preventDefault: () => void;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
interface Clickable {
|
|
13
|
+
onClick(ev?: PreventableEvent): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useLink(isRemote?: boolean) {
|
|
14
17
|
const router = useRouter();
|
|
15
18
|
const blockRouter = useBlockRouter();
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
return <L extends Partial<LinkProps & Clickable>>(props: L): L & Clickable => ({
|
|
21
|
+
...props,
|
|
22
|
+
href: adjustHref(props.href),
|
|
23
|
+
'aria-label': props.text,
|
|
24
|
+
onClick: handlerDecorator(handleHref(props), props),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function adjustHref(href: string | undefined) {
|
|
28
|
+
const isRelativeToBase = !isRemote && href?.startsWith('/');
|
|
29
|
+
|
|
30
|
+
return projectSettings.BASE_PATH && href && isRelativeToBase
|
|
31
|
+
? joinPath(projectSettings.BASE_PATH, href)
|
|
32
|
+
: href;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handleHref({ href, target, onClick }: Partial<LinkProps & Clickable>) {
|
|
36
|
+
return (ev?: PreventableEvent) => {
|
|
37
|
+
onClick && onClick(ev);
|
|
38
|
+
|
|
19
39
|
if (isRemote || !isLocalURL(href, target)) {
|
|
20
|
-
//
|
|
40
|
+
// Default routing
|
|
21
41
|
return;
|
|
22
42
|
}
|
|
23
43
|
|
|
@@ -29,14 +49,5 @@ export function useLink(
|
|
|
29
49
|
router.push(href);
|
|
30
50
|
}
|
|
31
51
|
};
|
|
32
|
-
|
|
33
|
-
return (props) => ({
|
|
34
|
-
...props,
|
|
35
|
-
'aria-label': props.text,
|
|
36
|
-
onClick: handlerDecorator((ev?: { preventDefault: () => void }) => {
|
|
37
|
-
props.onClick && props.onClick(ev);
|
|
38
|
-
|
|
39
|
-
handleLocalURL(props.href, props.target)(ev);
|
|
40
|
-
}, props),
|
|
41
|
-
});
|
|
52
|
+
}
|
|
42
53
|
}
|
|
@@ -15,7 +15,7 @@ interface EventMap {
|
|
|
15
15
|
intersection: BlockIntersectionEvent;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const normalizeAnchor = (rawAnchor?: string) => rawAnchor?.replace('#', '');
|
|
18
|
+
const normalizeAnchor = (rawAnchor?: string) => rawAnchor?.replace('#', '') || '';
|
|
19
19
|
const getURLWithAnchor = (rawAnchor?: string) =>
|
|
20
20
|
`${globalThis.location?.pathname}#${normalizeAnchor(rawAnchor)}`;
|
|
21
21
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import type { FallbackMap } from '../../model/Fallback';
|
|
3
|
+
|
|
4
|
+
export const fallbackWCMSResource = (filename: string): FallbackMap => ({
|
|
5
|
+
[`/wcms-resources/${filename}.json`]: async () =>
|
|
6
|
+
JSON.parse(await readFile(`./content/wcms-resources/${filename}.json`, 'utf-8')),
|
|
7
|
+
});
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import type { Router } from '../../hooks/useRouter';
|
|
2
|
-
import { projectSettings } from '../../ProjectSettings';
|
|
3
1
|
import { isURL, withoutQuery } from '../../utils/url';
|
|
4
2
|
|
|
5
3
|
export const isHrefActive =
|
|
6
|
-
(router:
|
|
7
|
-
({ href }: { href?: string }): boolean =>
|
|
8
|
-
|
|
9
|
-
const relativeHref =
|
|
10
|
-
BASE_PATH && href?.startsWith(BASE_PATH) ? href.substring(BASE_PATH.length) : href;
|
|
11
|
-
|
|
12
|
-
return withoutQuery(isURL(href) ? router.href : router.pathname).startsWith(
|
|
13
|
-
withoutQuery(relativeHref),
|
|
14
|
-
);
|
|
15
|
-
};
|
|
4
|
+
(router: { href?: string; pathname: string }) =>
|
|
5
|
+
({ href }: { href?: string }): boolean =>
|
|
6
|
+
withoutQuery(isURL(href) ? router.href : router.pathname).startsWith(withoutQuery(href));
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Router } from '../../hooks/useRouter';
|
|
2
|
+
import { projectSettings } from '../../ProjectSettings';
|
|
2
3
|
import { isHrefActive } from './isHrefActive';
|
|
3
4
|
import { TopMenuItem } from './SitemapProps';
|
|
4
5
|
|
|
5
6
|
export const isTopItemActive =
|
|
6
7
|
(router: Router) =>
|
|
7
8
|
(topItem: TopMenuItem): boolean =>
|
|
8
|
-
|
|
9
|
+
projectSettings.BASE_PATH
|
|
10
|
+
? isHrefActive({ pathname: projectSettings.BASE_PATH })(topItem)
|
|
11
|
+
: topItem.items?.some(isHrefActive(router)) || isHrefActive(router)(topItem);
|
|
@@ -2,8 +2,8 @@ import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
|
2
2
|
import type { Fallback } from '../../model/Fallback';
|
|
3
3
|
import { fetchJSONUnsafe } from '../../utils/fetchJSON';
|
|
4
4
|
|
|
5
|
-
export function useSWRResource<Data>(
|
|
6
|
-
const { data } = useAsyncData<Data>(`/wcms-resources/${
|
|
5
|
+
export function useSWRResource<Data>(filename: string, fallback: Fallback = {}): Data {
|
|
6
|
+
const { data } = useAsyncData<Data>(`/wcms-resources/${filename}.json`, fetchJSONUnsafe, {
|
|
7
7
|
fallback,
|
|
8
8
|
});
|
|
9
9
|
|
|
@@ -26,7 +26,9 @@ useRouter.setup(() => {
|
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
28
|
href,
|
|
29
|
-
pathname:
|
|
29
|
+
pathname: projectSettings.BASE_PATH
|
|
30
|
+
? new URL(href).pathname.substring(projectSettings.BASE_PATH.length - 1)
|
|
31
|
+
: '',
|
|
30
32
|
query: {},
|
|
31
33
|
push: (url: string) => {
|
|
32
34
|
globalThis.history.pushState(null, '', url);
|
package/mobile/src/utils/url.ts
CHANGED
|
@@ -8,8 +8,8 @@ export const isLocalURL = (href: string | undefined, target?: Target) =>
|
|
|
8
8
|
|
|
9
9
|
export const isHash = (href?: string): href is `#${string}` => Boolean(href?.startsWith('#'));
|
|
10
10
|
|
|
11
|
-
export const withoutQuery = (href?: string): string =>
|
|
11
|
+
export const withoutQuery = (href?: string): string =>
|
|
12
|
+
(href || '').replace(/\?.*/, '').replace(/\/$/, '');
|
|
12
13
|
|
|
13
|
-
export const
|
|
14
|
-
|
|
15
|
-
export const getHash = (href?: string) => (isURL(href) ? new URL(href).hash : undefined);
|
|
14
|
+
export const joinPath = (...path: string[]): string =>
|
|
15
|
+
path.filter(Boolean).join('/').replace(/\/+/g, '/');
|
package/package.json
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
1
|
import type { FallbackMap } from '../../model/Fallback';
|
|
3
2
|
import { projectSettings } from '../../ProjectSettings';
|
|
3
|
+
import { fallbackWCMSResource } from '../../services/sitemap/fallbackWCMSResource';
|
|
4
4
|
|
|
5
5
|
export const fallback = (): FallbackMap => ({
|
|
6
6
|
...fallbackWCMSResource(projectSettings.SITEMAP || 'sitemap'),
|
|
7
7
|
...fallbackWCMSResource(projectSettings.FOOTER || 'footer'),
|
|
8
8
|
});
|
|
9
|
-
|
|
10
|
-
const fallbackWCMSResource = (filename: string): FallbackMap => ({
|
|
11
|
-
[filename]: async () =>
|
|
12
|
-
JSON.parse(await readFile(`./content/wcms-resources/${filename}.json`, 'utf-8')),
|
|
13
|
-
});
|
|
@@ -3,25 +3,21 @@ import { useLink } from '../../hooks/useLink';
|
|
|
3
3
|
import type { Fallback } from '../../model/Fallback';
|
|
4
4
|
import type { LinkProps } from '../../model/LinkProps';
|
|
5
5
|
import { projectSettings } from '../../ProjectSettings';
|
|
6
|
-
import { mergeTopItems } from '../../services/sitemap/mergeTopItems';
|
|
7
6
|
import type { SitemapDataProps, TopMenuItem } from '../../services/sitemap/SitemapProps';
|
|
8
7
|
import { useSWRResource } from '../../services/sitemap/useSWRResource';
|
|
9
8
|
|
|
10
9
|
export interface SitemapProps {
|
|
11
10
|
className?: string;
|
|
12
|
-
items?: TopMenuItem[];
|
|
13
11
|
fallback?: Fallback;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
export const Sitemap = JSX<SitemapProps>(({ className = '',
|
|
14
|
+
export const Sitemap = JSX<SitemapProps>(({ className = '', fallback }) => {
|
|
17
15
|
const link = useLink();
|
|
18
|
-
|
|
19
16
|
const sitemap = useSWRResource<SitemapDataProps>(projectSettings.SITEMAP || 'sitemap', fallback);
|
|
20
|
-
const mergedItems = mergeTopItems(sitemap.topItems, items);
|
|
21
17
|
|
|
22
18
|
return (
|
|
23
19
|
<div className={`flex flex-grow items-start justify-between gap-[54px] xl:gap-5 ${className}`}>
|
|
24
|
-
{
|
|
20
|
+
{sitemap.topItems?.map((_, i) => renderColumn(link(_), i))}
|
|
25
21
|
</div>
|
|
26
22
|
);
|
|
27
23
|
});
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
1
|
import { projectSettings } from '../../ProjectSettings';
|
|
3
|
-
import
|
|
2
|
+
import { fallbackWCMSResource } from '../../services/sitemap/fallbackWCMSResource';
|
|
4
3
|
|
|
5
|
-
export const fallback = ()
|
|
6
|
-
[`/wcms-resources/${projectSettings.SITEMAP || 'sitemap'}.json`]: async () => {
|
|
7
|
-
const data = await readFile(
|
|
8
|
-
`./content/wcms-resources/${projectSettings.SITEMAP || 'sitemap'}.json`,
|
|
9
|
-
'utf-8',
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
return JSON.parse(data);
|
|
13
|
-
},
|
|
14
|
-
});
|
|
4
|
+
export const fallback = () => fallbackWCMSResource(projectSettings.SITEMAP || 'sitemap');
|
package/src/hooks/useLink.ts
CHANGED
|
@@ -1,23 +1,43 @@
|
|
|
1
|
-
import type { LinkProps
|
|
1
|
+
import type { LinkProps } from '../model/LinkProps';
|
|
2
|
+
import { projectSettings } from '../ProjectSettings';
|
|
2
3
|
import { useBlockRouter } from '../services/BlockRouter/useBlockRouter';
|
|
3
|
-
import { isHash, isLocalURL } from '../utils/url';
|
|
4
|
+
import { isHash, isLocalURL, joinPath } from '../utils/url';
|
|
4
5
|
import { handlerDecorator } from './handlerDecorator';
|
|
5
6
|
import { useRouter } from './useRouter';
|
|
6
7
|
|
|
7
|
-
interface
|
|
8
|
-
|
|
8
|
+
interface PreventableEvent {
|
|
9
|
+
preventDefault: () => void;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
interface Clickable {
|
|
13
|
+
onClick(ev?: PreventableEvent): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useLink(isRemote?: boolean) {
|
|
14
17
|
const router = useRouter();
|
|
15
18
|
const blockRouter = useBlockRouter();
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
return <L extends Partial<LinkProps & Clickable>>(props: L): L & Clickable => ({
|
|
21
|
+
...props,
|
|
22
|
+
href: adjustHref(props.href),
|
|
23
|
+
'aria-label': props.text,
|
|
24
|
+
onClick: handlerDecorator(handleHref(props), props),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function adjustHref(href: string | undefined) {
|
|
28
|
+
const isRelativeToBase = !isRemote && href?.startsWith('/');
|
|
29
|
+
|
|
30
|
+
return projectSettings.BASE_PATH && href && isRelativeToBase
|
|
31
|
+
? joinPath(projectSettings.BASE_PATH, href)
|
|
32
|
+
: href;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handleHref({ href, target, onClick }: Partial<LinkProps & Clickable>) {
|
|
36
|
+
return (ev?: PreventableEvent) => {
|
|
37
|
+
onClick && onClick(ev);
|
|
38
|
+
|
|
19
39
|
if (isRemote || !isLocalURL(href, target)) {
|
|
20
|
-
//
|
|
40
|
+
// Default routing
|
|
21
41
|
return;
|
|
22
42
|
}
|
|
23
43
|
|
|
@@ -29,14 +49,5 @@ export function useLink(
|
|
|
29
49
|
router.push(href);
|
|
30
50
|
}
|
|
31
51
|
};
|
|
32
|
-
|
|
33
|
-
return (props) => ({
|
|
34
|
-
...props,
|
|
35
|
-
'aria-label': props.text,
|
|
36
|
-
onClick: handlerDecorator((ev?: { preventDefault: () => void }) => {
|
|
37
|
-
props.onClick && props.onClick(ev);
|
|
38
|
-
|
|
39
|
-
handleLocalURL(props.href, props.target)(ev);
|
|
40
|
-
}, props),
|
|
41
|
-
});
|
|
52
|
+
}
|
|
42
53
|
}
|
|
@@ -15,7 +15,7 @@ interface EventMap {
|
|
|
15
15
|
intersection: BlockIntersectionEvent;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const normalizeAnchor = (rawAnchor?: string) => rawAnchor?.replace('#', '');
|
|
18
|
+
const normalizeAnchor = (rawAnchor?: string) => rawAnchor?.replace('#', '') || '';
|
|
19
19
|
const getURLWithAnchor = (rawAnchor?: string) =>
|
|
20
20
|
`${globalThis.location?.pathname}#${normalizeAnchor(rawAnchor)}`;
|
|
21
21
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import type { FallbackMap } from '../../model/Fallback';
|
|
3
|
+
|
|
4
|
+
export const fallbackWCMSResource = (filename: string): FallbackMap => ({
|
|
5
|
+
[`/wcms-resources/${filename}.json`]: async () =>
|
|
6
|
+
JSON.parse(await readFile(`./content/wcms-resources/${filename}.json`, 'utf-8')),
|
|
7
|
+
});
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import type { Router } from '../../hooks/useRouter';
|
|
2
|
-
import { projectSettings } from '../../ProjectSettings';
|
|
3
1
|
import { isURL, withoutQuery } from '../../utils/url';
|
|
4
2
|
|
|
5
3
|
export const isHrefActive =
|
|
6
|
-
(router:
|
|
7
|
-
({ href }: { href?: string }): boolean =>
|
|
8
|
-
|
|
9
|
-
const relativeHref =
|
|
10
|
-
BASE_PATH && href?.startsWith(BASE_PATH) ? href.substring(BASE_PATH.length) : href;
|
|
11
|
-
|
|
12
|
-
return withoutQuery(isURL(href) ? router.href : router.pathname).startsWith(
|
|
13
|
-
withoutQuery(relativeHref),
|
|
14
|
-
);
|
|
15
|
-
};
|
|
4
|
+
(router: { href?: string; pathname: string }) =>
|
|
5
|
+
({ href }: { href?: string }): boolean =>
|
|
6
|
+
withoutQuery(isURL(href) ? router.href : router.pathname).startsWith(withoutQuery(href));
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { Router } from '../../hooks/useRouter';
|
|
2
|
+
import { projectSettings } from '../../ProjectSettings';
|
|
2
3
|
import { isHrefActive } from './isHrefActive';
|
|
3
4
|
import { TopMenuItem } from './SitemapProps';
|
|
4
5
|
|
|
5
6
|
export const isTopItemActive =
|
|
6
7
|
(router: Router) =>
|
|
7
8
|
(topItem: TopMenuItem): boolean =>
|
|
8
|
-
|
|
9
|
+
projectSettings.BASE_PATH
|
|
10
|
+
? isHrefActive({ pathname: projectSettings.BASE_PATH })(topItem)
|
|
11
|
+
: topItem.items?.some(isHrefActive(router)) || isHrefActive(router)(topItem);
|
|
@@ -2,8 +2,8 @@ import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
|
2
2
|
import type { Fallback } from '../../model/Fallback';
|
|
3
3
|
import { fetchJSONUnsafe } from '../../utils/fetchJSON';
|
|
4
4
|
|
|
5
|
-
export function useSWRResource<Data>(
|
|
6
|
-
const { data } = useAsyncData<Data>(`/wcms-resources/${
|
|
5
|
+
export function useSWRResource<Data>(filename: string, fallback: Fallback = {}): Data {
|
|
6
|
+
const { data } = useAsyncData<Data>(`/wcms-resources/${filename}.json`, fetchJSONUnsafe, {
|
|
7
7
|
fallback,
|
|
8
8
|
});
|
|
9
9
|
|
package/src/setup-fixture.ts
CHANGED
|
@@ -26,7 +26,9 @@ useRouter.setup(() => {
|
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
28
|
href,
|
|
29
|
-
pathname:
|
|
29
|
+
pathname: projectSettings.BASE_PATH
|
|
30
|
+
? new URL(href).pathname.substring(projectSettings.BASE_PATH.length - 1)
|
|
31
|
+
: '',
|
|
30
32
|
query: {},
|
|
31
33
|
push: (url: string) => {
|
|
32
34
|
globalThis.history.pushState(null, '', url);
|
package/src/utils/url.ts
CHANGED
|
@@ -8,8 +8,8 @@ export const isLocalURL = (href: string | undefined, target?: Target) =>
|
|
|
8
8
|
|
|
9
9
|
export const isHash = (href?: string): href is `#${string}` => Boolean(href?.startsWith('#'));
|
|
10
10
|
|
|
11
|
-
export const withoutQuery = (href?: string): string =>
|
|
11
|
+
export const withoutQuery = (href?: string): string =>
|
|
12
|
+
(href || '').replace(/\?.*/, '').replace(/\/$/, '');
|
|
12
13
|
|
|
13
|
-
export const
|
|
14
|
-
|
|
15
|
-
export const getHash = (href?: string) => (isURL(href) ? new URL(href).hash : undefined);
|
|
14
|
+
export const joinPath = (...path: string[]): string =>
|
|
15
|
+
path.filter(Boolean).join('/').replace(/\/+/g, '/');
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.mergeTopItems = void 0;
|
|
3
|
-
const cmp = (a) => (b) => a?.href === b?.href;
|
|
4
|
-
const substitute = (items, substitution) => (items || []).map((_) => substitution?.find(cmp(_)) || _);
|
|
5
|
-
const subtract = (minuend, subtrahend) => (minuend || []).filter((_) => !subtrahend?.find(cmp(_)));
|
|
6
|
-
const mergeTopItems = (left, right) => substitute(left, right).concat(subtract(right, left));
|
|
7
|
-
exports.mergeTopItems = mergeTopItems;
|
|
8
|
-
//# sourceMappingURL=mergeTopItems.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTopItems.js","sourceRoot":"","sources":["../../../src/services/sitemap/mergeTopItems.ts"],"names":[],"mappings":";;AAEA,MAAM,GAAG,GAAG,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC;AAEtE,MAAM,UAAU,GAAG,CAAsB,KAAW,EAAE,YAAkB,EAAO,EAAE,CAC/E,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAE5D,MAAM,QAAQ,GAAG,CAAsB,OAAa,EAAE,UAAgB,EAAO,EAAE,CAC7E,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpD,MAAM,aAAa,GAAG,CAAsB,IAAU,EAAE,KAAW,EAAO,EAAE,CACjF,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAD3C,QAAA,aAAa,iBAC8B"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
const cmp = (a) => (b) => a?.href === b?.href;
|
|
2
|
-
const substitute = (items, substitution) => (items || []).map((_) => substitution?.find(cmp(_)) || _);
|
|
3
|
-
const subtract = (minuend, subtrahend) => (minuend || []).filter((_) => !subtrahend?.find(cmp(_)));
|
|
4
|
-
export const mergeTopItems = (left, right) => substitute(left, right).concat(subtract(right, left));
|
|
5
|
-
//# sourceMappingURL=mergeTopItems.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTopItems.js","sourceRoot":"","sources":["../../../src/services/sitemap/mergeTopItems.ts"],"names":[],"mappings":"AAEA,MAAM,GAAG,GAAG,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC;AAEtE,MAAM,UAAU,GAAG,CAAsB,KAAW,EAAE,YAAkB,EAAO,EAAE,CAC/E,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAE5D,MAAM,QAAQ,GAAG,CAAsB,OAAa,EAAE,UAAgB,EAAO,EAAE,CAC7E,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAsB,IAAU,EAAE,KAAW,EAAO,EAAE,CACjF,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.mergeTopItems = void 0;
|
|
3
|
-
const cmp = (a) => (b) => a?.href === b?.href;
|
|
4
|
-
const substitute = (items, substitution) => (items || []).map((_) => substitution?.find(cmp(_)) || _);
|
|
5
|
-
const subtract = (minuend, subtrahend) => (minuend || []).filter((_) => !subtrahend?.find(cmp(_)));
|
|
6
|
-
const mergeTopItems = (left, right) => substitute(left, right).concat(subtract(right, left));
|
|
7
|
-
exports.mergeTopItems = mergeTopItems;
|
|
8
|
-
//# sourceMappingURL=mergeTopItems.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTopItems.js","sourceRoot":"","sources":["../../../src/services/sitemap/mergeTopItems.ts"],"names":[],"mappings":";;AAEA,MAAM,GAAG,GAAG,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,CAAa,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC;AAEtE,MAAM,UAAU,GAAG,CAAsB,KAAW,EAAE,YAAkB,EAAO,EAAE,CAC/E,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAE5D,MAAM,QAAQ,GAAG,CAAsB,OAAa,EAAE,UAAgB,EAAO,EAAE,CAC7E,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpD,MAAM,aAAa,GAAG,CAAsB,IAAU,EAAE,KAAW,EAAO,EAAE,CACjF,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAD3C,QAAA,aAAa,iBAC8B"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
const cmp = (a) => (b) => a?.href === b?.href;
|
|
2
|
-
const substitute = (items, substitution) => (items || []).map((_) => substitution?.find(cmp(_)) || _);
|
|
3
|
-
const subtract = (minuend, subtrahend) => (minuend || []).filter((_) => !subtrahend?.find(cmp(_)));
|
|
4
|
-
export const mergeTopItems = (left, right) => substitute(left, right).concat(subtract(right, left));
|
|
5
|
-
//# sourceMappingURL=mergeTopItems.js.map
|