nextpress-core 1.0.3 → 2.0.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.
Files changed (211) hide show
  1. package/cli/install.js +27 -0
  2. package/{dist/acf-functions/core/acf-builder.js → lib/acf-functions/core/acf-builder.ts} +45 -17
  3. package/{dist/acf-functions/core/acf-component-autoloader.js → lib/acf-functions/core/acf-component-autoloader.ts} +13 -7
  4. package/{dist/acf-functions/core/acf-field-group-autoloader.js → lib/acf-functions/core/acf-field-group-autoloader.ts} +11 -5
  5. package/{dist/acf-functions/services/define-field-group.d.ts → lib/acf-functions/services/define-field-group.ts} +4 -1
  6. package/{dist/acf-functions/services/define-layout.d.ts → lib/acf-functions/services/define-layout.ts} +4 -1
  7. package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +20 -0
  8. package/{dist/acf-functions/services/map-fields/map-fields.js → lib/acf-functions/services/map-fields/map-fields.ts} +128 -89
  9. package/{dist/acf-functions/types/acf-field-group.d.ts → lib/acf-functions/types/acf-field-group.ts} +49 -28
  10. package/lib/acf-functions/types/acf-field.ts +2853 -0
  11. package/lib/acf-functions/types/acf-layout.ts +22 -0
  12. package/lib/acf-functions/types/components/field-props.ts +189 -0
  13. package/{dist/acf-functions/types/components/nextpress-component.d.ts → lib/acf-functions/types/components/nextpress-component.ts} +4 -3
  14. package/lib/ambient.d.ts +16 -0
  15. package/{dist/entities/common.d.ts → lib/entities/common.ts} +6 -4
  16. package/{dist/entities/option/option.interface.d.ts → lib/entities/option/option.interface.ts} +3 -3
  17. package/{dist/entities/option/option.js → lib/entities/option/option.ts} +21 -14
  18. package/{dist/entities/post/post.interface.d.ts → lib/entities/post/post.interface.ts} +26 -21
  19. package/lib/entities/post/post.ts +209 -0
  20. package/{dist/entities/term/term.interface.d.ts → lib/entities/term/term.interface.ts} +3 -3
  21. package/lib/entities/term/term.ts +82 -0
  22. package/{dist/entities/user/user.interface.d.ts → lib/entities/user/user.interface.ts} +2 -1
  23. package/lib/entities/user/user.ts +86 -0
  24. package/{dist/globals/entity-loader/entity-loader-base.js → lib/globals/entity-loader/entity-loader-base.ts} +64 -10
  25. package/{dist/globals/entity-loader/entity-loader.interface.d.ts → lib/globals/entity-loader/entity-loader.ts} +2 -4
  26. package/lib/globals/entity-loader/option-loader.ts +56 -0
  27. package/lib/globals/entity-loader/post-loader.ts +60 -0
  28. package/lib/globals/entity-loader/term-loader.ts +60 -0
  29. package/lib/globals/entity-loader/user-loader.ts +61 -0
  30. package/lib/globals/get-field/get-field.ts +76 -0
  31. package/{dist/globals/globals.js → lib/globals/globals.ts} +8 -3
  32. package/{dist/globals/nextpress-config/nextpress-config.interface.d.ts → lib/globals/nextpress-config/nextpress-config.interface.ts} +10 -6
  33. package/lib/globals/nextpress-config/nextpress-config.ts +8 -0
  34. package/lib/globals/queried-object/queried-object.ts +124 -0
  35. package/{dist/repository/optionquery/option-query-args.d.ts → lib/repository/optionquery/option-query-args.ts} +5 -2
  36. package/lib/repository/optionquery/option-query.ts +29 -0
  37. package/{dist/repository/postquery/post-query-args.d.ts → lib/repository/postquery/post-query-args.ts} +10 -6
  38. package/lib/repository/postquery/post-query.ts +282 -0
  39. package/{dist/repository/termquery/term-query-args.d.ts → lib/repository/termquery/term-query-args.ts} +16 -6
  40. package/lib/repository/termquery/term-query.ts +244 -0
  41. package/{dist/repository/userquery/user-query-args.d.ts → lib/repository/userquery/user-query-args.ts} +19 -7
  42. package/{dist/repository/userquery/user-query.js → lib/repository/userquery/user-query.ts} +93 -76
  43. package/{dist/router/helpers.js → lib/router/helpers.ts} +4 -4
  44. package/{dist/router/nextpress-layout.js → lib/router/nextpress-layout.tsx} +28 -9
  45. package/{dist/router/routes/not-found-page.js → lib/router/nextpress-not-found-route.tsx} +7 -5
  46. package/{dist/router/nextpress-proxy.js → lib/router/nextpress-proxy.ts} +15 -3
  47. package/{dist/router/nextpress-static-params.js → lib/router/nextpress-static-params.ts} +17 -5
  48. package/{dist/router/router.js → lib/router/router.tsx} +29 -22
  49. package/{dist/router/routes/api/api-get-admin-bar.js → lib/router/routes/api/api-get-admin-bar.ts} +8 -6
  50. package/{dist/router/routes/api/api-get-draft-mode.js → lib/router/routes/api/api-get-draft-mode.ts} +15 -6
  51. package/{dist/router/routes/api/api-get-field-groups.js → lib/router/routes/api/api-get-field-groups.ts} +13 -8
  52. package/{dist/router/routes/api/api-post-revalidate.js → lib/router/routes/api/api-post-revalidate.ts} +6 -4
  53. package/{dist/router/routes/api/helpers.js → lib/router/routes/api/helpers.ts} +4 -3
  54. package/lib/router/routes/author-archive.tsx +75 -0
  55. package/lib/router/routes/post-index-page.tsx +58 -0
  56. package/lib/router/routes/singular-page.tsx +78 -0
  57. package/lib/router/routes/site-front-page.tsx +51 -0
  58. package/lib/router/routes/term-archive.tsx +93 -0
  59. package/{dist/router/types.d.ts → lib/router/types.ts} +4 -2
  60. package/{dist/services/get-menu.js → lib/services/get-menu.ts} +56 -32
  61. package/{dist/services/get-theme-mods.js → lib/services/get-theme-mods.ts} +6 -4
  62. package/{dist/services/metadata/get-blogname.js → lib/services/metadata/get-blogname.ts} +2 -2
  63. package/{dist/services/metadata/get-favicon-url.js → lib/services/metadata/get-favicon-url.ts} +5 -4
  64. package/{dist/services/metadata/get-language-attribute.js → lib/services/metadata/get-language-attribute.ts} +1 -1
  65. package/{dist/services/utilities/capitalise-first-letter.js → lib/services/utilities/capitalise-first-letter.ts} +2 -3
  66. package/{dist/services/utilities/esc-html.js → lib/services/utilities/esc-html.ts} +3 -1
  67. package/{dist/services/utilities/get-date-time-formatter.js → lib/services/utilities/get-date-time-formatter.ts} +16 -6
  68. package/{dist/services/utilities/kses-post.js → lib/services/utilities/kses-post.ts} +2 -1
  69. package/{dist/services/utilities/process-url.js → lib/services/utilities/process-url.ts} +4 -3
  70. package/{dist/template-heirarchy/_autoloader/template-autoloader.js → lib/template-heirarchy/_autoloader/template-autoloader.ts} +18 -9
  71. package/{dist/template-heirarchy/archive/archive.js → lib/template-heirarchy/archive/archive.tsx} +10 -7
  72. package/{dist/template-heirarchy/archive/author.js → lib/template-heirarchy/archive/author.tsx} +10 -7
  73. package/{dist/template-heirarchy/archive/category.js → lib/template-heirarchy/archive/category.tsx} +11 -7
  74. package/{dist/template-heirarchy/archive/posttypearchive.js → lib/template-heirarchy/archive/posttypearchive.tsx} +11 -8
  75. package/{dist/template-heirarchy/archive/tag.js → lib/template-heirarchy/archive/tag.tsx} +12 -7
  76. package/{dist/template-heirarchy/archive/taxonomy.js → lib/template-heirarchy/archive/taxonomy.tsx} +10 -7
  77. package/{dist/template-heirarchy/home/home.js → lib/template-heirarchy/home/home.tsx} +10 -7
  78. package/{dist/template-heirarchy/index.js → lib/template-heirarchy/index.tsx} +9 -5
  79. package/{dist/template-heirarchy/not-found.tsx/not-found.js → lib/template-heirarchy/not-found.tsx/not-found.tsx} +10 -7
  80. package/{dist/template-heirarchy/page/page.js → lib/template-heirarchy/page/page.tsx} +10 -7
  81. package/{dist/template-heirarchy/page/posttype.js → lib/template-heirarchy/page/posttype.tsx} +12 -8
  82. package/{dist/template-heirarchy/page/single.js → lib/template-heirarchy/page/single.tsx} +10 -7
  83. package/{dist/template-heirarchy/page/singular.js → lib/template-heirarchy/page/singular.tsx} +10 -7
  84. package/lib/ui/render-attachment-image.tsx +28 -0
  85. package/lib/ui/render-components.tsx +12 -0
  86. package/lib/ui/render-the-admin-bar.tsx +79 -0
  87. package/lib/ui/render-the-logo.tsx +24 -0
  88. package/{dist/wpdb/wpdb.interface.d.ts → lib/wpdb/wpdb.interface.ts} +20 -1
  89. package/{dist/wpdb/wpdb.js → lib/wpdb/wpdb.ts} +9 -5
  90. package/package.json +8 -15
  91. package/dist/acf-functions/core/acf-builder.d.ts +0 -51
  92. package/dist/acf-functions/core/acf-component-autoloader.d.ts +0 -11
  93. package/dist/acf-functions/core/acf-field-group-autoloader.d.ts +0 -10
  94. package/dist/acf-functions/field-props.d.ts +0 -196
  95. package/dist/acf-functions/field-props.js +0 -1
  96. package/dist/acf-functions/services/define-field-group.js +0 -10
  97. package/dist/acf-functions/services/define-layout.js +0 -10
  98. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +0 -2
  99. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +0 -18
  100. package/dist/acf-functions/services/map-fields/map-fields.d.ts +0 -21
  101. package/dist/acf-functions/types/acf-field-group.js +0 -1
  102. package/dist/acf-functions/types/acf-field.d.ts +0 -2813
  103. package/dist/acf-functions/types/acf-field.js +0 -1
  104. package/dist/acf-functions/types/acf-layout.d.ts +0 -19
  105. package/dist/acf-functions/types/acf-layout.js +0 -1
  106. package/dist/acf-functions/types/acf-values.js +0 -1
  107. package/dist/acf-functions/types/components/field-props.d.ts +0 -196
  108. package/dist/acf-functions/types/components/field-props.js +0 -1
  109. package/dist/acf-functions/types/components/nextpress-component.js +0 -1
  110. package/dist/entities/common.js +0 -1
  111. package/dist/entities/option/option.d.ts +0 -19
  112. package/dist/entities/option/option.interface.js +0 -2
  113. package/dist/entities/post/post.d.ts +0 -50
  114. package/dist/entities/post/post.interface.js +0 -2
  115. package/dist/entities/post/post.js +0 -184
  116. package/dist/entities/term/term.d.ts +0 -28
  117. package/dist/entities/term/term.interface.js +0 -1
  118. package/dist/entities/term/term.js +0 -67
  119. package/dist/entities/user/user.d.ts +0 -27
  120. package/dist/entities/user/user.interface.js +0 -1
  121. package/dist/entities/user/user.js +0 -74
  122. package/dist/globals/entity-loader/entity-loader-base.d.ts +0 -65
  123. package/dist/globals/entity-loader/entity-loader.interface.js +0 -1
  124. package/dist/globals/entity-loader/option-loader.d.ts +0 -15
  125. package/dist/globals/entity-loader/option-loader.js +0 -31
  126. package/dist/globals/entity-loader/post-loader.d.ts +0 -21
  127. package/dist/globals/entity-loader/post-loader.js +0 -28
  128. package/dist/globals/entity-loader/term-loader.d.ts +0 -21
  129. package/dist/globals/entity-loader/term-loader.js +0 -28
  130. package/dist/globals/entity-loader/user-loader.d.ts +0 -21
  131. package/dist/globals/entity-loader/user-loader.js +0 -28
  132. package/dist/globals/get-field/get-field.d.ts +0 -18
  133. package/dist/globals/get-field/get-field.js +0 -44
  134. package/dist/globals/globals.d.ts +0 -18
  135. package/dist/globals/nextpress-config/nextpress-config.d.ts +0 -4
  136. package/dist/globals/nextpress-config/nextpress-config.interface.js +0 -1
  137. package/dist/globals/nextpress-config/nextpress-config.js +0 -2
  138. package/dist/globals/queried-object/queried-object.d.ts +0 -62
  139. package/dist/globals/queried-object/queried-object.js +0 -56
  140. package/dist/repository/optionquery/option-query-args.js +0 -1
  141. package/dist/repository/optionquery/option-query.d.ts +0 -12
  142. package/dist/repository/optionquery/option-query.js +0 -20
  143. package/dist/repository/postquery/post-query-args.js +0 -1
  144. package/dist/repository/postquery/post-query.d.ts +0 -12
  145. package/dist/repository/postquery/post-query.js +0 -272
  146. package/dist/repository/termquery/term-query-args.js +0 -1
  147. package/dist/repository/termquery/term-query.d.ts +0 -11
  148. package/dist/repository/termquery/term-query.js +0 -213
  149. package/dist/repository/userquery/user-query-args.js +0 -1
  150. package/dist/repository/userquery/user-query.d.ts +0 -12
  151. package/dist/router/helpers.d.ts +0 -14
  152. package/dist/router/nextpress-layout.d.ts +0 -11
  153. package/dist/router/nextpress-proxy.d.ts +0 -8
  154. package/dist/router/nextpress-static-params.d.ts +0 -9
  155. package/dist/router/router.d.ts +0 -23
  156. package/dist/router/routes/api/api-get-admin-bar.d.ts +0 -8
  157. package/dist/router/routes/api/api-get-draft-mode.d.ts +0 -8
  158. package/dist/router/routes/api/api-get-field-groups.d.ts +0 -7
  159. package/dist/router/routes/api/api-post-revalidate.d.ts +0 -7
  160. package/dist/router/routes/api/helpers.d.ts +0 -8
  161. package/dist/router/routes/author-archive.d.ts +0 -25
  162. package/dist/router/routes/author-archive.js +0 -49
  163. package/dist/router/routes/not-found-page.d.ts +0 -15
  164. package/dist/router/routes/post-index-page.d.ts +0 -25
  165. package/dist/router/routes/post-index-page.js +0 -33
  166. package/dist/router/routes/singular-page.d.ts +0 -29
  167. package/dist/router/routes/singular-page.js +0 -51
  168. package/dist/router/routes/site-front-page.d.ts +0 -27
  169. package/dist/router/routes/site-front-page.js +0 -26
  170. package/dist/router/routes/term-archive.d.ts +0 -29
  171. package/dist/router/routes/term-archive.js +0 -65
  172. package/dist/router/types.js +0 -1
  173. package/dist/services/get-menu.d.ts +0 -13
  174. package/dist/services/get-theme-mods.d.ts +0 -7
  175. package/dist/services/metadata/get-blogname.d.ts +0 -6
  176. package/dist/services/metadata/get-favicon-url.d.ts +0 -6
  177. package/dist/services/metadata/get-language-attribute.d.ts +0 -6
  178. package/dist/services/services.d.ts +0 -3
  179. package/dist/services/services.js +0 -3
  180. package/dist/services/utilities/capitalise-first-letter.d.ts +0 -7
  181. package/dist/services/utilities/esc-html.d.ts +0 -7
  182. package/dist/services/utilities/get-date-time-formatter.d.ts +0 -6
  183. package/dist/services/utilities/index.d.ts +0 -0
  184. package/dist/services/utilities/index.js +0 -1
  185. package/dist/services/utilities/kses-post.d.ts +0 -7
  186. package/dist/services/utilities/process-url.d.ts +0 -7
  187. package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +0 -9
  188. package/dist/template-heirarchy/archive/archive.d.ts +0 -16
  189. package/dist/template-heirarchy/archive/author.d.ts +0 -16
  190. package/dist/template-heirarchy/archive/category.d.ts +0 -16
  191. package/dist/template-heirarchy/archive/posttypearchive.d.ts +0 -24
  192. package/dist/template-heirarchy/archive/tag.d.ts +0 -16
  193. package/dist/template-heirarchy/archive/taxonomy.d.ts +0 -16
  194. package/dist/template-heirarchy/home/home.d.ts +0 -16
  195. package/dist/template-heirarchy/index.d.ts +0 -17
  196. package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +0 -16
  197. package/dist/template-heirarchy/page/page.d.ts +0 -16
  198. package/dist/template-heirarchy/page/posttype.d.ts +0 -24
  199. package/dist/template-heirarchy/page/single.d.ts +0 -16
  200. package/dist/template-heirarchy/page/singular.d.ts +0 -16
  201. package/dist/ui/render-attachment-image.d.ts +0 -12
  202. package/dist/ui/render-attachment-image.js +0 -24
  203. package/dist/ui/render-components.d.ts +0 -9
  204. package/dist/ui/render-components.js +0 -7
  205. package/dist/ui/render-the-admin-bar.d.ts +0 -8
  206. package/dist/ui/render-the-admin-bar.js +0 -36
  207. package/dist/ui/render-the-logo.d.ts +0 -10
  208. package/dist/ui/render-the-logo.js +0 -16
  209. package/dist/wpdb/wpdb.d.ts +0 -3
  210. package/dist/wpdb/wpdb.interface.js +0 -5
  211. /package/{dist/acf-functions/types/acf-values.d.ts → lib/acf-functions/types/acf-values.ts} +0 -0
@@ -0,0 +1,51 @@
1
+ import { queriedObjectState } from "nextpress/globals/globals";
2
+ import { MetadataResult, RouteProps, TemplateResult } from "../types";
3
+ import { PostIndexPage } from "./post-index-page";
4
+ import { PageMetadata, PageTemplate } from "nextpress/template-heirarchy/page/page";
5
+
6
+ /**
7
+ * Resolves the site front page route and maps it to the template hierarchy to return Metadata.
8
+ * * Routing Behavior:
9
+ * - If a static page is set as the homepage ('page_on_front'), it routes to `PageMetadata`.
10
+ * - If no static page is set, it delegates routing to `PostIndexPage`.
11
+ *
12
+ * @param {{ path: string[], metadata: true }} props - Route properties requesting metadata.
13
+ * @returns {Promise<MetadataResult>} The generated metadata.
14
+ */
15
+ export function SiteFrontPage(props: { path: string[], metadata: true }): Promise<MetadataResult>;
16
+
17
+ /**
18
+ * Resolves the site front page route and maps it to the template hierarchy to return a Template.
19
+ * * Routing Behavior:
20
+ * - If a static page is set as the homepage ('page_on_front'), it routes to `PageTemplate`.
21
+ * - If no static page is set, it delegates routing to `PostIndexPage`.
22
+ *
23
+ * @param {{ path: string[], metadata?: false }} props - Route properties requesting a template.
24
+ * @returns {Promise<TemplateResult>} The rendered template component.
25
+ */
26
+ export function SiteFrontPage(props: { path: string[], metadata?: false }): Promise<TemplateResult>;
27
+
28
+ /**
29
+ * Core implementation for the site front page (root) route.
30
+ * Checks for a configured static front page and updates the queried object state.
31
+ *
32
+ * @param {RouteProps} props - Route properties including the path array and metadata flag.
33
+ * @returns {Promise<MetadataResult | TemplateResult>} The metadata or template result based on the hierarchy.
34
+ */
35
+ export async function SiteFrontPage({ path, metadata = false }: RouteProps) {
36
+ const homepageId = Number(await getOption('page_on_front'));
37
+
38
+ if (homepageId) {
39
+ const currentQueriedObject = {
40
+ objectType: 'post',
41
+ posts: [homepageId]
42
+ }
43
+
44
+ const state = queriedObjectState();
45
+ state.currentState = currentQueriedObject;
46
+
47
+ return metadata ? await PageMetadata() : <PageTemplate/>;
48
+ } else {
49
+ return metadata ? await PostIndexPage({path, metadata: true}) : <PostIndexPage path={path}/>
50
+ }
51
+ }
@@ -0,0 +1,93 @@
1
+ import { MetadataResult, RouteProps, TemplateResult } from "../types";
2
+ import { getPageNumber } from "../helpers";
3
+ import { notFound } from "next/navigation";
4
+ import { queriedObjectState } from "nextpress/globals/globals";
5
+ import { CategoryMetadata, CategoryTemplate } from "nextpress/template-heirarchy/archive/category";
6
+ import { TagMetadata, TagTemplate } from "nextpress/template-heirarchy/archive/tag";
7
+ import { TaxonomyMetadata, TaxonomyTemplate } from "nextpress/template-heirarchy/archive/taxonomy";
8
+
9
+ /**
10
+ * Resolves the term archive route and maps it to the template hierarchy to return Metadata.
11
+ * * Routing Behavior:
12
+ * - If the taxonomy is 'category', it routes to `CategoryMetadata`.
13
+ * - If the taxonomy is 'tag', it routes to `TagMetadata`.
14
+ * - For all other taxonomies, it routes to `TaxonomyMetadata`.
15
+ *
16
+ * @param {{ path: string[], metadata: true }} props - Route properties requesting metadata.
17
+ * @returns {Promise<MetadataResult>} The generated metadata.
18
+ */
19
+ export function TermArchive(props: { path: string[], metadata: true }): Promise<MetadataResult>;
20
+
21
+ /**
22
+ * Resolves the term archive route and maps it to the template hierarchy to return a Template.
23
+ * * Routing Behavior:
24
+ * - If the taxonomy is 'category', it routes to `CategoryTemplate`.
25
+ * - If the taxonomy is 'tag', it routes to `TagTemplate`.
26
+ * - For all other taxonomies, it routes to `TaxonomyTemplate`.
27
+ *
28
+ * @param {{ path: string[], metadata?: false }} props - Route properties requesting a template.
29
+ * @returns {Promise<TemplateResult>} The rendered template component.
30
+ */
31
+ export function TermArchive(props: { path: string[], metadata?: false }): Promise<TemplateResult>;
32
+
33
+ /**
34
+ * Core implementation for the term archive route.
35
+ * Retrieves posts for a specific taxonomy term and updates the queried object state.
36
+ *
37
+ * @param {RouteProps} props - Route properties including the path array and metadata flag.
38
+ * @returns {Promise<MetadataResult | TemplateResult>} The metadata or template result based on the hierarchy.
39
+ * @throws {Error} Throws a Next.js notFound error if the term does not exist.
40
+ */
41
+ export async function TermArchive({ path, metadata = false }: RouteProps) {
42
+ const postsPerPage = Number(await getOption('posts_per_page')) ?? 10;
43
+
44
+ let page = getPageNumber(path);
45
+ if (page) {
46
+ path = path.slice(0, -2);
47
+ } else {
48
+ page = 1;
49
+ }
50
+
51
+ const taxonomy = path[0] ?? '';
52
+ const pathString = path.slice(1).join('/');
53
+
54
+ const termQuery = await termLoader.findAndPrime({
55
+ taxonomy,
56
+ path: `/${pathString}`
57
+ });
58
+ if (!termQuery.ids.length) notFound();
59
+
60
+ const postIds = await postLoader.findAndPrime({
61
+ termIn: termQuery.ids,
62
+ noFoundRows: false,
63
+ noPaging: false,
64
+ postType: 'post',
65
+ page: page,
66
+ postsPerPage: postsPerPage,
67
+ postStatus: 'publish',
68
+ orderBy: 'date'
69
+ });
70
+
71
+ const terms = await getTerms(termQuery.ids);
72
+ const mainTerm = terms.find(term => term.slug === path[path.length - 1])!;
73
+
74
+ const currentQueriedObject = {
75
+ objectType: 'term',
76
+ posts: postIds.ids,
77
+ page,
78
+ pageCount: Math.ceil(postIds.count / postsPerPage),
79
+ mainTerm: mainTerm.termId,
80
+ terms: termQuery.ids
81
+ };
82
+
83
+ const state = queriedObjectState();
84
+ state.currentState = currentQueriedObject;
85
+
86
+ if (taxonomy === 'category') {
87
+ return metadata ? await CategoryMetadata() : <CategoryTemplate/>;
88
+ } else if (taxonomy === 'tag') {
89
+ return metadata ? await TagMetadata() : <TagTemplate/>;
90
+ } else {
91
+ return metadata ? await TaxonomyMetadata() : <TaxonomyTemplate/>;
92
+ }
93
+ }
@@ -1,8 +1,10 @@
1
1
  import { Metadata } from "next";
2
- import { JSX } from "react/jsx-runtime";
2
+ import { JSX } from "react";
3
+
3
4
  export type TemplateResult = JSX.Element;
4
5
  export type MetadataResult = Metadata;
6
+
5
7
  export type RouteProps = {
6
8
  path: string[];
7
9
  metadata?: boolean;
8
- };
10
+ }
@@ -1,80 +1,104 @@
1
+ import { IMenuItem } from "../entities/post/post.interface";
1
2
  import { getThemeMods } from "./get-theme-mods";
3
+
4
+ type Menu = {
5
+ menuItem: IMenuItem,
6
+ children: Menu[]
7
+ }
8
+
2
9
  /**
3
10
  * Retrieves a menu by its location identifier.
4
11
  *
5
12
  * @param {string} menuLocation - The location identifier of the menu.
6
13
  * @returns {Promise<Menu[] | undefined>} An array of menu items representing the menu tree, or undefined if the menu is not found.
7
14
  */
8
- export async function getMenu(menuLocation) {
9
- var _a, _b, _c, _d;
15
+ export async function getMenu(menuLocation: string): Promise<Menu[] | undefined> {
10
16
  const navMenuLocations = await getThemeMods('nav_menu_locations');
11
- if (!navMenuLocations || typeof navMenuLocations !== 'object')
12
- return;
13
- const menuTermId = Number(navMenuLocations[menuLocation]) || undefined;
14
- if (!menuTermId)
15
- return;
17
+ if (!navMenuLocations || typeof navMenuLocations !== 'object') return;
18
+
19
+ const menuTermId = Number((navMenuLocations as Record<string, any>)[menuLocation]) || undefined;
20
+ if (!menuTermId) return;
21
+
16
22
  const postQuery = await postLoader.findAndPrime({
17
23
  termId: menuTermId,
18
24
  postStatus: 'publish',
19
25
  postType: 'nav_menu_item',
20
26
  noFoundRows: true,
21
27
  noPaging: true
22
- });
23
- const menuItems = (await getPosts(postQuery.ids)).sort((a, b) => a.menuOrder - b.menuOrder);
28
+ })
29
+
30
+ const menuItems: IMenuItem[] = (await getPosts(postQuery.ids)).sort((a, b) => a.menuOrder - b.menuOrder);
31
+
24
32
  // Prime cache to get paths in bunch later
25
33
  for (const item of menuItems) {
26
- if (!item.menuItemAttributes)
27
- continue;
34
+ if (!item.menuItemAttributes) continue;
35
+
28
36
  if (item.menuItemAttributes.type === 'post_type') {
29
- postLoader.prime([item.menuItemAttributes.objectId]);
30
- }
31
- else if (item.menuItemAttributes.type === 'taxonomy') {
32
- termLoader.prime([item.menuItemAttributes.objectId]);
37
+ postLoader.prime([item.menuItemAttributes.objectId])
38
+ } else if (item.menuItemAttributes.type === 'taxonomy') {
39
+ termLoader.prime([item.menuItemAttributes.objectId])
33
40
  }
34
41
  }
35
- const map = new Map();
36
- const tree = [];
42
+
43
+ const map = new Map<number, Menu>();
44
+ const tree: Menu[] = [];
45
+
37
46
  for (const item of menuItems) {
38
- if (!item.menuItemAttributes)
39
- continue;
40
- const menuItemAttributes = Object.assign({}, item.menuItemAttributes);
47
+ if (!item.menuItemAttributes) continue;
48
+
49
+ const menuItemAttributes = { ...item.menuItemAttributes };
50
+
41
51
  if (item.menuItemAttributes.type === 'post_type') {
42
52
  const post = await getPost(menuItemAttributes.objectId);
43
- menuItemAttributes.url = (_a = post === null || post === void 0 ? void 0 : post.path) !== null && _a !== void 0 ? _a : '';
53
+
54
+ menuItemAttributes.url = post?.path ?? '';
55
+
44
56
  if (!menuItemAttributes.label) {
45
- menuItemAttributes.label = (_b = post === null || post === void 0 ? void 0 : post.postTitle) !== null && _b !== void 0 ? _b : '';
57
+ menuItemAttributes.label = post?.postTitle ?? '';
46
58
  }
47
- }
48
- else if (item.menuItemAttributes.type === 'taxonomy') {
59
+ } else if (item.menuItemAttributes.type === 'taxonomy') {
49
60
  const term = await getTerm(menuItemAttributes.objectId);
50
- menuItemAttributes.url = (_c = term === null || term === void 0 ? void 0 : term.path) !== null && _c !== void 0 ? _c : '';
61
+
62
+ menuItemAttributes.url = term?.path ?? '';
63
+
51
64
  if (!menuItemAttributes.label) {
52
- menuItemAttributes.label = (_d = term === null || term === void 0 ? void 0 : term.name) !== null && _d !== void 0 ? _d : '';
65
+ menuItemAttributes.label = term?.name ?? '';
53
66
  }
54
67
  }
55
- const safeItem = Object.assign(Object.assign({}, item), { menuItemAttributes });
56
- const node = {
68
+
69
+ const safeItem: IMenuItem = {
70
+ ...item,
71
+ menuItemAttributes
72
+ };
73
+
74
+ const node: Menu = {
57
75
  menuItem: safeItem,
58
76
  children: []
59
77
  };
78
+
60
79
  map.set(item.ID, node);
61
80
  }
81
+
62
82
  for (const item of menuItems) {
63
- if (!item.menuItemAttributes)
64
- continue;
83
+ if (!item.menuItemAttributes) continue;
84
+
65
85
  const currentNode = map.get(item.ID);
66
- if (!currentNode)
67
- continue;
86
+ if (!currentNode) continue;
87
+
68
88
  const parentId = item.menuItemAttributes.parentId;
89
+
69
90
  if (parentId === 0) {
70
91
  tree.push(currentNode);
71
92
  continue;
72
93
  }
94
+
73
95
  const parentNode = map.get(parentId);
96
+
74
97
  if (parentNode) {
75
98
  parentNode.children.push(currentNode);
76
99
  map.set(parentNode.menuItem.ID, parentNode);
77
100
  }
78
101
  }
102
+
79
103
  return tree;
80
104
  }
@@ -1,14 +1,16 @@
1
1
  import { unserialize } from "php-serialize";
2
+
2
3
  /**
3
4
  * Retrieves a theme modification value by key.
4
5
  *
5
6
  * @param {string} key - The key of the theme modification to retrieve.
6
7
  * @returns {Promise<unknown | undefined>} The theme modification value, or undefined if not found.
7
8
  */
8
- export async function getThemeMods(key) {
9
+ export async function getThemeMods(key: string): Promise<unknown | undefined> {
9
10
  const themeModOption = await getOption('theme_mods_nextpress_theme');
10
- const themeMods = unserialize(themeModOption !== null && themeModOption !== void 0 ? themeModOption : 'a:0:{}');
11
- if (Array.isArray(themeMods))
12
- return;
11
+
12
+ const themeMods: Record<string, unknown> | unknown[] = unserialize(themeModOption ?? 'a:0:{}');
13
+ if (Array.isArray(themeMods)) return;
14
+
13
15
  return themeMods[key];
14
16
  }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns {Promise<string>} The blog name, defaulting to 'My Blog' if not found.
5
5
  */
6
- export async function getBlogname() {
6
+ export async function getBlogname(): Promise<string> {
7
7
  const blognameOption = await getOption('blogname');
8
- return blognameOption !== null && blognameOption !== void 0 ? blognameOption : 'My Blog';
8
+ return blognameOption ?? 'My Blog';
9
9
  }
@@ -3,10 +3,11 @@
3
3
  *
4
4
  * @returns {Promise<string|undefined>} The URL of the favicon, or undefined if not set.
5
5
  */
6
- export async function getFaviconURL() {
6
+ export async function getFaviconURL(): Promise<string|undefined> {
7
7
  const iconID = await getOption('site_icon');
8
- if (!iconID)
9
- return;
8
+ if (!iconID) return;
9
+
10
10
  const iconMediaPost = await getPost(Number(iconID));
11
- return iconMediaPost === null || iconMediaPost === void 0 ? void 0 : iconMediaPost.guid;
11
+
12
+ return iconMediaPost?.guid;
12
13
  }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @returns {Promise<string>} The language attribute, defaulting to 'en_US' if not found.
5
5
  */
6
- export async function getLanguageAttributes() {
6
+ export async function getLanguageAttributes(): Promise<string> {
7
7
  const wplang = await getOption('WPLANG');
8
8
  return wplang || 'en_US';
9
9
  }
@@ -4,8 +4,7 @@
4
4
  * @param {string} string - The string to process.
5
5
  * @returns {string} The string with its first letter capitalized.
6
6
  */
7
- export function capitalizeFirstLetter(string) {
8
- if (!string)
9
- return string;
7
+ export function capitalizeFirstLetter(string: string): string {
8
+ if (!string) return string;
10
9
  return string.charAt(0).toUpperCase() + string.slice(1);
11
10
  }
@@ -1,10 +1,12 @@
1
1
  import DOMPurify from "isomorphic-dompurify";
2
+
2
3
  /**
3
4
  * Sanitizes an HTML string.
4
5
  *
5
6
  * @param {string} string - The string to sanitize.
6
7
  * @returns {string} The sanitized string.
7
8
  */
8
- export function escHtml(string) {
9
+ export function escHtml(string: string) {
9
10
  return DOMPurify.sanitize(string);
10
11
  }
12
+
@@ -1,39 +1,49 @@
1
1
  import { getLanguageAttributes } from "../metadata/get-language-attribute";
2
+
2
3
  /**
3
4
  * Creates a DateTimeFormat instance based on WordPress settings.
4
5
  *
5
6
  * @returns {Promise<Intl.DateTimeFormat>} The formatter instance.
6
7
  */
7
- export async function getDateTimeFormatter() {
8
- var _a;
9
- const dateFormat = (_a = await getOption('date_format')) !== null && _a !== void 0 ? _a : 'F j, Y';
8
+ export async function getDateTimeFormatter(): Promise<Intl.DateTimeFormat> {
9
+ const dateFormat = await getOption('date_format') ?? 'F j, Y';
10
10
  const lang = await getLanguageAttributes();
11
- const dateTimeOptionsMap = {
11
+
12
+ const dateTimeOptionsMap: Record<string, Intl.DateTimeFormatOptions> = {
12
13
  'd': { day: '2-digit' },
13
14
  'j': { day: 'numeric' },
15
+
14
16
  'l': { weekday: 'long' },
15
17
  'D': { weekday: 'short' },
18
+
16
19
  'm': { month: '2-digit' },
17
20
  'n': { month: 'numeric' },
18
21
  'F': { month: 'long' },
19
22
  'M': { month: 'short' },
23
+
20
24
  'Y': { year: 'numeric' },
21
25
  'y': { year: '2-digit' },
26
+
22
27
  'a': { hour12: true },
23
28
  'A': { hour12: true },
29
+
24
30
  'g': { hour: 'numeric', hour12: true },
25
31
  'h': { hour: '2-digit', hour12: true },
26
32
  'G': { hour: 'numeric', hour12: false },
27
33
  'H': { hour: '2-digit', hour12: false },
34
+
28
35
  'i': { minute: '2-digit' },
29
36
  's': { second: '2-digit' },
37
+
30
38
  'T': { timeZoneName: 'short' }
31
39
  };
40
+
32
41
  const dateTimeOptions = dateFormat.split('').reduce((options, char) => {
33
42
  if (dateTimeOptionsMap[char]) {
34
- return Object.assign(Object.assign({}, options), dateTimeOptionsMap[char]);
43
+ return { ...options, ...dateTimeOptionsMap[char] };
35
44
  }
36
45
  return options;
37
- }, {});
46
+ }, {} as Intl.DateTimeFormatOptions);
47
+
38
48
  return new Intl.DateTimeFormat(lang.replace('_', '-'), dateTimeOptions);
39
49
  }
@@ -1,12 +1,13 @@
1
1
  import parse from 'html-react-parser';
2
2
  import DOMPurify from "isomorphic-dompurify";
3
+
3
4
  /**
4
5
  * Sanitizes and parses an HTML string into React elements.
5
6
  *
6
7
  * @param {string} html - The HTML string to process.
7
8
  * @returns {string | JSX.Element | JSX.Element[]} The parsed React elements.
8
9
  */
9
- export function wpKsesPost(html) {
10
+ export function ksesPost(html: string) {
10
11
  const cleanHtml = DOMPurify.sanitize(html, { USE_PROFILES: { html: true } });
11
12
  return parse(cleanHtml);
12
13
  }
@@ -4,11 +4,12 @@
4
4
  * @param {string} url - The URL to process.
5
5
  * @returns {string} The processed URL.
6
6
  */
7
- export function processURL(url) {
8
- if (!process.env.WP_SITE_URL)
9
- return url;
7
+ export function processURL(url: string): string {
8
+ if (!process.env.WP_SITE_URL) return url;
9
+
10
10
  if (url.startsWith(process.env.WP_SITE_URL)) {
11
11
  url = url.slice(process.env.WP_SITE_URL.length);
12
12
  }
13
+
13
14
  return url || '/';
14
15
  }
@@ -1,5 +1,7 @@
1
1
  import fs from 'fs';
2
+ import { Metadata } from 'next';
2
3
  import path from 'path';
4
+
3
5
  /**
4
6
  * Loads a specified export suffix from a given template file.
5
7
  *
@@ -7,39 +9,46 @@ import path from 'path';
7
9
  * @param {'Metadata' | 'Template'} exportSuffix - The suffix of the export to retrieve from the file.
8
10
  * @returns {Promise<any | undefined>} The requested export, or undefined if not found or an error occurs.
9
11
  */
10
- async function loadFile(template, exportSuffix) {
12
+ async function loadFile(template: string, exportSuffix: 'Metadata' | 'Template'): Promise<any | undefined> {
11
13
  const absolutePath = path.join(process.cwd(), 'src', 'app', '_templates');
12
14
  const files = fs.readdirSync(absolutePath);
13
- const imports = [];
15
+
16
+ const imports: any[] = [];
17
+
14
18
  for (const file of files) {
15
- if (file !== (`${template.toLowerCase()}.tsx`))
16
- continue;
19
+ if (file !== (`${template.toLowerCase()}.tsx`)) continue;
20
+
17
21
  try {
18
22
  const imported = await import(`@/app/_templates/${file}`);
23
+
19
24
  const exported = imported[`${template}${exportSuffix}`];
25
+
20
26
  imports.push(exported);
21
- }
22
- catch (_error) {
27
+ } catch (_error) {
23
28
  return undefined;
24
29
  }
25
30
  }
31
+
26
32
  return imports[0];
27
33
  }
34
+
28
35
  /**
29
36
  * Loads the exported metadata configuration for a given template.
30
37
  *
31
38
  * @param {string} template - The name of the template file to load metadata from.
32
39
  * @returns {Promise<Metadata | undefined>} The metadata object, or undefined if the metadata does not exist.
33
40
  */
34
- export async function loadMetadata(template) {
41
+ export async function loadMetadata(template: string): Promise<Metadata | undefined> {
35
42
  const metadataFn = await loadFile(template, 'Metadata');
36
43
  if (metadataFn) {
37
44
  return typeof metadataFn === 'function' ? metadataFn() : metadataFn;
38
45
  }
39
46
  }
40
- export async function loadTemplate(template) {
47
+
48
+ export async function loadTemplate(template: string): Promise<React.ComponentType<any> | undefined> {
41
49
  const element = await loadFile(template, 'Template');
42
50
  if (element) {
43
- return element;
51
+ return element as React.ComponentType<any>;
44
52
  }
45
53
  }
54
+
@@ -1,25 +1,28 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { Metadata } from "next";
2
+ import { JSX } from "react";
2
3
  import { loadMetadata, loadTemplate } from "../_autoloader/template-autoloader";
3
4
  import { IndexMetadata, IndexTemplate } from "..";
5
+
4
6
  /**
5
7
  * Loads the metadata for the Archive template.
6
8
  * Fallback: Index
7
9
  *
8
10
  * @returns {Promise<Metadata>} The merged metadata object.
9
11
  */
10
- export async function ArchiveMetadata() {
12
+ export async function ArchiveMetadata(): Promise<Metadata> {
11
13
  const metadata = await loadMetadata('Archive');
12
- return Object.assign(Object.assign({}, (await IndexMetadata())), metadata);
14
+ return {...(await IndexMetadata()), ...metadata};
13
15
  }
16
+
14
17
  /**
15
18
  * Renders the Archive template. Falls back to the Index template if not found.
16
19
  * Fallback: Index
17
20
  *
18
21
  * @returns {Promise<JSX.Element>} The rendered template component.
19
22
  */
20
- export async function ArchiveTemplate() {
23
+ export async function ArchiveTemplate(): Promise<JSX.Element> {
21
24
  const Archive = await loadTemplate('Archive');
22
- if (!Archive)
23
- return _jsx(IndexTemplate, {});
24
- return _jsx(Archive, {});
25
+ if (!Archive) return <IndexTemplate/>
26
+
27
+ return <Archive/>;
25
28
  }
@@ -1,25 +1,28 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { Metadata } from "next";
2
+ import { JSX } from "react";
2
3
  import { loadMetadata, loadTemplate } from "../_autoloader/template-autoloader";
3
4
  import { ArchiveMetadata, ArchiveTemplate } from "./archive";
5
+
4
6
  /**
5
7
  * Loads the metadata for the Author template.
6
8
  * Fallback: Archive
7
9
  *
8
10
  * @returns {Promise<Metadata>} The merged metadata object.
9
11
  */
10
- export async function AuthorMetadata() {
12
+ export async function AuthorMetadata(): Promise<Metadata> {
11
13
  const metadata = await loadMetadata('Author');
12
- return Object.assign(Object.assign({}, (await ArchiveMetadata())), metadata);
14
+ return {...(await ArchiveMetadata()), ...metadata};
13
15
  }
16
+
14
17
  /**
15
18
  * Renders the Author template. Falls back to the Archive template if not found.
16
19
  * Fallback: Archive
17
20
  *
18
21
  * @returns {Promise<JSX.Element>} The rendered template component.
19
22
  */
20
- export async function AuthorTemplate() {
23
+ export async function AuthorTemplate(): Promise<JSX.Element> {
21
24
  const Author = await loadTemplate('Author');
22
- if (!Author)
23
- return _jsx(ArchiveTemplate, {});
24
- return _jsx(Author, {});
25
+ if (!Author) return <ArchiveTemplate/>
26
+
27
+ return <Author/>;
25
28
  }
@@ -1,25 +1,29 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { Metadata } from "next";
2
+ import { JSX } from "react";
2
3
  import { loadMetadata, loadTemplate } from "../_autoloader/template-autoloader";
3
4
  import { ArchiveMetadata, ArchiveTemplate } from "./archive";
5
+
4
6
  /**
5
7
  * Loads the metadata for the Category template.
6
8
  * Fallback: Archive
7
9
  *
8
10
  * @returns {Promise<Metadata>} The merged metadata object.
9
11
  */
10
- export async function CategoryMetadata() {
12
+ export async function CategoryMetadata(): Promise<Metadata> {
11
13
  const metadata = await loadMetadata('Category');
12
- return Object.assign(Object.assign({}, (await ArchiveMetadata())), metadata);
14
+ return {...(await ArchiveMetadata()), ...metadata};
13
15
  }
16
+
14
17
  /**
15
18
  * Renders the Category template. Falls back to the Archive template if not found.
16
19
  * Fallback: Archive
17
20
  *
18
21
  * @returns {Promise<JSX.Element>} The rendered template component.
19
22
  */
20
- export async function CategoryTemplate() {
23
+ export async function CategoryTemplate(): Promise<JSX.Element> {
21
24
  const Category = await loadTemplate('Category');
22
- if (!Category)
23
- return _jsx(ArchiveTemplate, {});
24
- return _jsx(Category, {});
25
+ if (!Category) return <ArchiveTemplate/>
26
+
27
+ return <Category/>;
25
28
  }
29
+