From ebc5e0fa5c5d4c2c060aba5542f8dac5bd90ba11 Mon Sep 17 00:00:00 2001 From: Jirka Svoboda Date: Tue, 17 Dec 2024 09:29:46 +0100 Subject: [PATCH] fix(templates): removed unused compileHref from page template and fixed generateViewport function fixes #320 --- examples/basic/yarn.lock | 114 +++++++++++++++++- .../decorators/with-page-metadata.ts | 1 + .../decorators/with-page-viewport.ts | 9 +- src/cli/templates/page-tpl.test.ts | 65 ++++++++-- src/cli/templates/page-tpl.ts | 2 +- 5 files changed, 173 insertions(+), 18 deletions(-) diff --git a/examples/basic/yarn.lock b/examples/basic/yarn.lock index 486ca1f..b1af363 100644 --- a/examples/basic/yarn.lock +++ b/examples/basic/yarn.lock @@ -881,6 +881,11 @@ resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406" integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ== +"@yarnpkg/lockfile@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" + integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ== + acorn-jsx@^5.3.2: version "5.3.2" resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" @@ -1282,7 +1287,7 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw== -chalk@^4.0.0, chalk@^4.1.0: +chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -1310,6 +1315,11 @@ chokidar@^3.6.0: optionalDependencies: fsevents "~2.3.2" +ci-info@^3.7.0: + version "3.9.0" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.9.0.tgz#4279a62028a7b1f262f3473fc9605f5e218c59b4" + integrity sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ== + ci-info@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-4.1.0.tgz#92319d2fa29d2620180ea5afed31f589bc98cf83" @@ -2250,6 +2260,13 @@ find-up@^5.0.0: locate-path "^6.0.0" path-exists "^4.0.0" +find-yarn-workspace-root@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/find-yarn-workspace-root/-/find-yarn-workspace-root-2.0.0.tgz#f47fb8d239c900eb78179aa81b66673eac88f7bd" + integrity sha512-1IMnbjt4KzsQfnhnzNd8wUEgXZ44IzZaZmnLYx7D5FZlaHt2gW20Cri8Q+E/t5tIj4+epTBub+2Zxu/vNILzqQ== + dependencies: + micromatch "^4.0.2" + flat-cache@^3.0.4: version "3.2.0" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.2.0.tgz#2c0c2d5040c99b1632771a9d105725c0115363ee" @@ -2308,7 +2325,7 @@ from@~0: resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe" integrity sha512-twe20eF1OxVxp/ML/kq2p1uc6KvFK/+vs8WjEbeKmV2He22MKm7YF2ANIt+EOqhJ5L3K/SuuPhk0hWQDjOM23g== -fs-extra@^9.1.0: +fs-extra@^9.0.0, fs-extra@^9.1.0: version "9.1.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d" integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ== @@ -2492,7 +2509,7 @@ gopd@^1.0.1: dependencies: get-intrinsic "^1.1.3" -graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4: +graceful-fs@^4.1.11, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4: version "4.2.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== @@ -2704,6 +2721,11 @@ is-date-object@^1.0.5: dependencies: has-tostringtag "^1.0.0" +is-docker@^2.0.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa" + integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ== + is-extglob@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" @@ -2851,6 +2873,13 @@ is-weakset@^2.0.3: call-bind "^1.0.7" get-intrinsic "^1.2.4" +is-wsl@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" + integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== + dependencies: + is-docker "^2.0.0" + isarray@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723" @@ -2939,6 +2968,16 @@ json-stable-stringify-without-jsonify@^1.0.1: resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651" integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw== +json-stable-stringify@^1.0.2: + version "1.1.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.1.1.tgz#52d4361b47d49168bcc4e564189a42e5a7439454" + integrity sha512-SU/971Kt5qVQfJpyDveVhQ/vya+5hvrjClFOcr8c0Fq5aODJjMwutrOfCU+eCnVD5gpx1Q3fEqkyom77zH1iIg== + dependencies: + call-bind "^1.0.5" + isarray "^2.0.5" + jsonify "^0.0.1" + object-keys "^1.1.1" + json-stringify-safe@~5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" @@ -2960,6 +2999,11 @@ jsonfile@^6.0.1: optionalDependencies: graceful-fs "^4.1.6" +jsonify@^0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.1.tgz#2aa3111dae3d34a0f151c63f3a45d995d9420978" + integrity sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg== + jsprim@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-2.0.2.tgz#77ca23dbcd4135cd364800d22ff82c2185803d4d" @@ -2987,6 +3031,13 @@ keyv@^4.5.3: dependencies: json-buffer "3.0.1" +klaw-sync@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-6.0.0.tgz#1fd2cfd56ebb6250181114f0a581167099c2b28c" + integrity sha512-nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ== + dependencies: + graceful-fs "^4.1.11" + language-subtag-registry@^0.3.20: version "0.3.23" resolved "https://registry.yarnpkg.com/language-subtag-registry/-/language-subtag-registry-0.3.23.tgz#23529e04d9e3b74679d70142df3fd2eb6ec572e7" @@ -3118,7 +3169,7 @@ merge2@^1.3.0, merge2@^1.4.1: resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== -micromatch@^4.0.4, micromatch@^4.0.8: +micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.8: version "4.0.8" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202" integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA== @@ -3338,6 +3389,14 @@ onetime@^5.1.0, onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" +open@^7.4.2: + version "7.4.2" + resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321" + integrity sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q== + dependencies: + is-docker "^2.0.0" + is-wsl "^2.1.1" + opener@^1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598" @@ -3355,6 +3414,11 @@ optionator@^0.9.3: type-check "^0.4.0" word-wrap "^1.2.5" +os-tmpdir@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + integrity sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g== + ospath@^1.2.2: version "1.2.2" resolved "https://registry.yarnpkg.com/ospath/-/ospath-1.2.2.tgz#1276639774a3f8ef2572f7fe4280e0ea4550c07b" @@ -3398,6 +3462,27 @@ parse-typed-args@^0.2.0: resolved "https://registry.yarnpkg.com/parse-typed-args/-/parse-typed-args-0.2.0.tgz#34c5c101659435cf75e9bcfa475135a29afe03d5" integrity sha512-xFLk7SuXQuOfXF9wim9Ti65WAEUqUWAL+QZvts/4MivXcESjvU74pKkp4rLj4hS63ZrvNAvpWLxvupE4wpqCWA== +patch-package@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/patch-package/-/patch-package-8.0.0.tgz#d191e2f1b6e06a4624a0116bcb88edd6714ede61" + integrity sha512-da8BVIhzjtgScwDJ2TtKsfT5JFWz1hYoBl9rUQ1f38MC2HwnEIkK8VN3dKMKcP7P7bvvgzNDbfNHtx3MsQb5vA== + dependencies: + "@yarnpkg/lockfile" "^1.1.0" + chalk "^4.1.2" + ci-info "^3.7.0" + cross-spawn "^7.0.3" + find-yarn-workspace-root "^2.0.0" + fs-extra "^9.0.0" + json-stable-stringify "^1.0.2" + klaw-sync "^6.0.0" + minimist "^1.2.6" + open "^7.4.2" + rimraf "^2.6.3" + semver "^7.5.3" + slash "^2.0.0" + tmp "^0.0.33" + yaml "^2.2.2" + path-exists@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" @@ -3729,6 +3814,13 @@ rfdc@^1.3.0: resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.4.1.tgz#778f76c4fb731d93414e8f925fbecf64cce7f6ca" integrity sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA== +rimraf@^2.6.3: + version "2.7.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" + integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w== + dependencies: + glob "^7.1.3" + rimraf@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" @@ -3895,6 +3987,11 @@ sirv@^2.0.3: mrmime "^2.0.0" totalist "^3.0.0" +slash@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-2.0.0.tgz#de552851a1759df3a8f206535442f5ec4ddeab44" + integrity sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A== + slash@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" @@ -4215,6 +4312,13 @@ tldts@^6.1.32: dependencies: tldts-core "^6.1.64" +tmp@^0.0.33: + version "0.0.33" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" + integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== + dependencies: + os-tmpdir "~1.0.2" + tmp@~0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.3.tgz#eb783cc22bc1e8bebd0671476d46ea4eb32a79ae" @@ -4551,7 +4655,7 @@ ws@^7.3.1: resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9" integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ== -yaml@^2.3.4: +yaml@^2.2.2, yaml@^2.3.4: version "2.6.1" resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.6.1.tgz#42f2b1ba89203f374609572d5349fb8686500773" integrity sha512-7r0XPzioN/Q9kXBro/XPnA6kznR73DHq+GXh5ON7ZozRO6aMjbmiBuKste2wslTFkC5d1dw0GooOCepZXJ2SAg== diff --git a/src/cli/templates/decorators/with-page-metadata.ts b/src/cli/templates/decorators/with-page-metadata.ts index f9b4794..8d66de4 100644 --- a/src/cli/templates/decorators/with-page-metadata.ts +++ b/src/cli/templates/decorators/with-page-metadata.ts @@ -27,6 +27,7 @@ export async function generateMetadata(props:any) { ` export const tplDynamicForDynamicRoute = ` +import { compileHref } from 'next-roots' import {generateMetadata as generateMetadataOrigin} from '${PATTERNS.originPath}' export async function generateMetadata({ params, ...otherProps }:any) { diff --git a/src/cli/templates/decorators/with-page-viewport.ts b/src/cli/templates/decorators/with-page-viewport.ts index 58be4cf..fc0b4e5 100644 --- a/src/cli/templates/decorators/with-page-viewport.ts +++ b/src/cli/templates/decorators/with-page-viewport.ts @@ -27,6 +27,7 @@ export function generateViewport({ searchParams, ...otherProps }:any) { ` export const tplDynamicForDynamicRoute = ` +import { compileHref } from 'next-roots' import {generateViewport as generateViewportOrigin} from '${PATTERNS.originPath}' export function generateViewport({ params, searchParams, ...otherProps }:any) { @@ -35,11 +36,11 @@ export function generateViewport({ params, searchParams, ...otherProps }:any) { } ` -export function withPageStaticMetaData(input: string) { +export function withPageStaticViewport(input: string) { return `${input}${tplStatic}` } -export function withPageDynamicMetaDataFactory(rewrite: Rewrite) { +export function withPageDynamicViewportFactory(rewrite: Rewrite) { return (input: string) => { let output = `${input}${ isDynamicRewrite(rewrite) @@ -59,11 +60,11 @@ export function withPageViewportDecoratorFactory( params: DecoratorParams ): CompileFn { if (params.getOriginContents().match(/export function generateViewport/g)) { - return withPageDynamicMetaDataFactory(params.getRewrite()) + return withPageDynamicViewportFactory(params.getRewrite()) } if (params.getOriginContents().match(/export const viewport/g)) { - return withPageStaticMetaData + return withPageStaticViewport } return (i: string) => i diff --git a/src/cli/templates/page-tpl.test.ts b/src/cli/templates/page-tpl.test.ts index 9e14447..754a58a 100644 --- a/src/cli/templates/page-tpl.test.ts +++ b/src/cli/templates/page-tpl.test.ts @@ -79,7 +79,7 @@ export default function AuthLoginPage(props:any) { test('should create page for [dynamic] route', () => { const expectedOutput = ` import BlogAuthorIdPageOrigin from '../../../../../roots/blog/[authorId]/page' -import { Router, compileHref } from 'next-roots' +import { Router } from 'next-roots' export default function BlogAuthorIdPage({ params, ...otherProps }) { Router.setLocale('cs') @@ -111,7 +111,7 @@ export default function BlogAuthorIdPage({ params, ...otherProps }) { test('should create page for [[...optionalCatchAll]] route', () => { const expectedOutput = ` import ProductsPageOrigin from '../../../../../roots/products/[[...slugs]]/page' -import { Router, compileHref } from 'next-roots' +import { Router } from 'next-roots' export default function ProductsPage({ params, ...otherProps }) { Router.setLocale('cs') @@ -204,6 +204,54 @@ export async function generateMetadata(props) { expect(output).toBe(expectedOutput) }) +test('should create page for [dynamic] route with generate static params and generateMetadata function', () => { + const expectedOutput = ` +import BlogAuthorIdPageOrigin from '../../../../../roots/blog/[authorId]/page' +import { Router } from 'next-roots' + +export default function BlogAuthorIdPage({ params, ...otherProps }:any) { + Router.setLocale('cs') + Router.setPageHref('/cs/magazin/:authorId') + Router.setParams(params) + {/* @ts-ignore */} + return +} + +import { compileHref } from 'next-roots' +import {generateMetadata as generateMetadataOrigin} from '../../../../../roots/blog/[authorId]/page' + +export async function generateMetadata({ params, ...otherProps }:any) { + const getPageHref = async () => compileHref('/cs/magazin/:authorId', await params) + return generateMetadataOrigin({ ...otherProps, params, locale: "cs", getPageHref }) +} + +import {generateStaticParams as generateStaticParamsOrigin} from '../../../../../roots/blog/[authorId]/page' + +export async function generateStaticParams({ params, ...otherProps }:any) { + return generateStaticParamsOrigin({ ...otherProps, params, pageLocale: "cs" }) +} +` + const inputRewrite = { + originPath: '/blog/[authorId]/page.ts', + localizedPath: '/cs/magazin/[authorId]/page.ts', + } + + const inputConfig = { + ...defaultConfig, + // resolves to = /src/app/cs/magazin/[authorId]/page.ts + getLocalizedAbsolutePath: (fileName = '') => + path.join('/src/app', fileName), + // resolves to = /roots/magazin/[authorId]/page.ts + getOriginAbsolutePath: (fileName = '') => path.join('/roots', fileName), + getOriginContents: () => + `export async function generateMetadata() {};export async function generateStaticParams() {}`, + } + + const compile = compileFactory(inputConfig) + const output = compile(inputRewrite) + expect(output).toBe(expectedOutput) +}) + test('should create page with static viewport object', () => { const expectedOutput = ` import StaticViewportPageOrigin from '..' @@ -267,10 +315,10 @@ export function generateViewport({ searchParams, ...otherProps }) { expect(output).toBe(expectedOutput) }) -test('should create page for [dynamic] route with generate static params and generateMetadata functions', () => { +test('should create page for [dynamic] route with generate static params and generateViewport function', () => { const expectedOutput = ` import BlogAuthorIdPageOrigin from '../../../../../roots/blog/[authorId]/page' -import { Router, compileHref } from 'next-roots' +import { Router } from 'next-roots' export default function BlogAuthorIdPage({ params, ...otherProps }:any) { Router.setLocale('cs') @@ -280,11 +328,12 @@ export default function BlogAuthorIdPage({ params, ...otherProps }:any) { return } -import {generateMetadata as generateMetadataOrigin} from '../../../../../roots/blog/[authorId]/page' +import { compileHref } from 'next-roots' +import {generateViewport as generateViewportOrigin} from '../../../../../roots/blog/[authorId]/page' -export async function generateMetadata({ params, ...otherProps }:any) { +export function generateViewport({ params, searchParams, ...otherProps }:any) { const getPageHref = async () => compileHref('/cs/magazin/:authorId', await params) - return generateMetadataOrigin({ ...otherProps, params, locale: "cs", getPageHref }) + return generateViewportOrigin({ ...otherProps, params, searchParams, locale: "cs", getPageHref }) } import {generateStaticParams as generateStaticParamsOrigin} from '../../../../../roots/blog/[authorId]/page' @@ -306,7 +355,7 @@ export async function generateStaticParams({ params, ...otherProps }:any) { // resolves to = /roots/magazin/[authorId]/page.ts getOriginAbsolutePath: (fileName = '') => path.join('/roots', fileName), getOriginContents: () => - `export async function generateMetadata() {};export async function generateStaticParams() {}`, + `export function generateViewport() {};export async function generateStaticParams() {}`, } const compile = compileFactory(inputConfig) diff --git a/src/cli/templates/page-tpl.ts b/src/cli/templates/page-tpl.ts index 686e75d..c568bc1 100644 --- a/src/cli/templates/page-tpl.ts +++ b/src/cli/templates/page-tpl.ts @@ -41,7 +41,7 @@ export default function ${PATTERNS.originName}(props:any) { export const tplDynamic = ` import ${PATTERNS.originName}Origin from '${PATTERNS.originPath}' -import { Router, compileHref } from 'next-roots' +import { Router } from 'next-roots' export default function ${PATTERNS.originName}({ params, ...otherProps }:any) { Router.setLocale('${PATTERNS.pageLocale}')