@mindful-web/marko-web-html-sitemap 1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Parameter1 LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,46 @@
1
+ import dayjs from "@mindful-web/dayjs";
2
+
3
+ $ const {
4
+ pageNode,
5
+ mountPoint,
6
+ year,
7
+ month,
8
+ day,
9
+ } = input;
10
+
11
+ <nav aria-label="breadcrumb">
12
+ <ol class="breadcrumb">
13
+ <if(mountPoint)>
14
+ <if(year)>
15
+ <if(month)>
16
+ <li class="breadcrumb-item">
17
+ <marko-web-link href=`${mountPoint}/${year}`>
18
+ ${year}
19
+ </marko-web-link>
20
+ </li>
21
+ $ const d = dayjs(`${month} ${year}`, "MMMM YYYY");
22
+ <if(day)>
23
+ <li class="breadcrumb-item">
24
+ <marko-web-link href=`${mountPoint}/${d.format("YYYY/MM")}`>
25
+ ${d.format("MMMM")}
26
+ </marko-web-link>
27
+ </li>
28
+ <li class="breadcrumb-item">
29
+ ${day}
30
+ </li>
31
+ </if>
32
+ <else>
33
+ <li class="breadcrumb-item">
34
+ ${d.format("MMMM")}
35
+ </li>
36
+ </else>
37
+ </if>
38
+ <else>
39
+ <li class="breadcrumb-item">
40
+ ${year}
41
+ </li>
42
+ </else>
43
+ </if>
44
+ </if>
45
+ </ol>
46
+ </nav>
@@ -0,0 +1,83 @@
1
+ // Compiled using marko@4.20.2 - DO NOT EDIT
2
+ "use strict";
3
+
4
+ var marko_template = module.exports = require("marko/dist/html").t(__filename),
5
+ marko_componentType = "/@mindful-web/marko-web-html-sitemap$1.0.0/components/breadcrumb.marko",
6
+ marko_renderer = require("marko/dist/runtime/components/renderer"),
7
+ module_dayjs = require("@mindful-web/dayjs"),
8
+ dayjs = module_dayjs.default || module_dayjs,
9
+ helpers_escape_xml = require("marko/dist/runtime/html/helpers/escape-xml"),
10
+ marko_escapeXml = helpers_escape_xml.x,
11
+ marko_web_link_template = require("@mindful-web/marko-web/components/element/link.marko"),
12
+ marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
13
+ marko_web_link_tag = marko_loadTag(marko_web_link_template);
14
+
15
+ function render(input, out, __component, component, state) {
16
+ var data = input;
17
+
18
+ const {
19
+ pageNode,
20
+ mountPoint,
21
+ year,
22
+ month,
23
+ day,
24
+ } = input;
25
+
26
+ out.w("<nav aria-label=\"breadcrumb\"><ol class=\"breadcrumb\">");
27
+
28
+ if (mountPoint) {
29
+ if (year) {
30
+ if (month) {
31
+ out.w("<li class=\"breadcrumb-item\">");
32
+
33
+ marko_web_link_tag({
34
+ href: (mountPoint + "/") + year,
35
+ renderBody: function(out) {
36
+ out.w(marko_escapeXml(year));
37
+ }
38
+ }, out, __component, "3");
39
+
40
+ out.w("</li>");
41
+
42
+ const d = dayjs(`${month} ${year}`, "MMMM YYYY");
43
+
44
+ if (day) {
45
+ out.w("<li class=\"breadcrumb-item\">");
46
+
47
+ marko_web_link_tag({
48
+ href: (mountPoint + "/") + d.format("YYYY/MM"),
49
+ renderBody: function(out) {
50
+ out.w(marko_escapeXml(d.format("MMMM")));
51
+ }
52
+ }, out, __component, "5");
53
+
54
+ out.w("</li><li class=\"breadcrumb-item\">" +
55
+ marko_escapeXml(day) +
56
+ "</li>");
57
+ } else {
58
+ out.w("<li class=\"breadcrumb-item\">" +
59
+ marko_escapeXml(d.format("MMMM")) +
60
+ "</li>");
61
+ }
62
+ } else {
63
+ out.w("<li class=\"breadcrumb-item\">" +
64
+ marko_escapeXml(year) +
65
+ "</li>");
66
+ }
67
+ }
68
+ }
69
+
70
+ out.w("</ol></nav>");
71
+ }
72
+
73
+ marko_template._ = marko_renderer(render, {
74
+ d_: true,
75
+ e_: marko_componentType
76
+ });
77
+
78
+ marko_template.meta = {
79
+ id: "/@mindful-web/marko-web-html-sitemap$1.0.0/components/breadcrumb.marko",
80
+ tags: [
81
+ "@mindful-web/marko-web/components/element/link.marko"
82
+ ]
83
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ "<marko-web-html-sitemap-breadcrumb>": {
3
+ "template": "./breadcrumb.marko"
4
+ },
5
+ "<marko-web-html-sitemap-pagination-controls>": {
6
+ "template": "./pagination-controls.marko"
7
+ },
8
+ "<marko-web-html-sitemap-query-total-count>": {
9
+ "template": "./query-total-count.marko"
10
+ }
11
+ }
@@ -0,0 +1,53 @@
1
+ import { URLSearchParams } from "url";
2
+ import { cleanPath } from "@mindful-web/utils";
3
+ import defaultValue from "@mindful-web/marko-core/utils/default-value";
4
+
5
+ $ const { perPage, totalCount, path } = input;
6
+ $ const asRels = defaultValue(input.asRels, false);
7
+ $ const { htmlSitemapPagination: p } = out.global;
8
+
9
+ $ const totalPages = p.totalPages({ perPage, totalCount });
10
+ $ const nextPage = p.nextPage({ perPage, totalCount });
11
+ $ const prevPage = p.prevPage();
12
+
13
+ $ const nextQuery = new URLSearchParams({ ...input.query, page: nextPage });
14
+ $ const prevQuery = new URLSearchParams({ ...input.query, page: prevPage });
15
+
16
+ $ const nextHref = `/${cleanPath(path)}?${nextQuery}`;
17
+ $ const prevHref = `/${cleanPath(path)}?${prevQuery}`;
18
+
19
+ $ const blockName = "pagination-controls";
20
+
21
+ <if(totalCount)>
22
+ <if(asRels)>
23
+ <if(prevPage)>
24
+ <link rel="prev" href=prevHref />
25
+ </if>
26
+ <if(nextPage)>
27
+ <link rel="next" href=nextHref />
28
+ </if>
29
+ </if>
30
+ <else>
31
+ <marko-web-block name=blockName class=input.class>
32
+ <if(prevPage)>
33
+ <marko-web-link
34
+ class=`btn btn-primary ${blockName}__prev`
35
+ href=prevHref
36
+ >
37
+ Previous Page
38
+ </marko-web-link>
39
+ </if>
40
+ <marko-web-element block-name=blockName name="pages">
41
+ Page ${p.page} of ${totalPages}
42
+ </marko-web-element>
43
+ <if(nextPage)>
44
+ <marko-web-link
45
+ class=`btn btn-primary ${blockName}__next`
46
+ href=nextHref
47
+ >
48
+ Next Page
49
+ </marko-web-link>
50
+ </if>
51
+ </marko-web-block>
52
+ </else>
53
+ </if>
@@ -0,0 +1,119 @@
1
+ // Compiled using marko@4.20.2 - DO NOT EDIT
2
+ "use strict";
3
+
4
+ var marko_template = module.exports = require("marko/dist/html").t(__filename),
5
+ marko_componentType = "/@mindful-web/marko-web-html-sitemap$1.0.0/components/pagination-controls.marko",
6
+ marko_renderer = require("marko/dist/runtime/components/renderer"),
7
+ module_url_module = require("url"),
8
+ url_module = module_url_module.default || module_url_module,
9
+ URLSearchParams = module_url_module.URLSearchParams,
10
+ module_utils_module = require("@mindful-web/utils"),
11
+ utils_module = module_utils_module.default || module_utils_module,
12
+ cleanPath = module_utils_module.cleanPath,
13
+ module_defaultValue = require("@mindful-web/marko-core/utils/default-value"),
14
+ defaultValue = module_defaultValue.default || module_defaultValue,
15
+ marko_attr = require("marko/dist/runtime/html/helpers/attr"),
16
+ marko_web_link_template = require("@mindful-web/marko-web/components/element/link.marko"),
17
+ marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
18
+ marko_web_link_tag = marko_loadTag(marko_web_link_template),
19
+ helpers_escape_xml = require("marko/dist/runtime/html/helpers/escape-xml"),
20
+ marko_escapeXml = helpers_escape_xml.x,
21
+ marko_web_element_template = require("@mindful-web/marko-web/components/element/index.marko"),
22
+ marko_web_element_tag = marko_loadTag(marko_web_element_template),
23
+ marko_web_block_template = require("@mindful-web/marko-web/components/element/block.marko"),
24
+ marko_web_block_tag = marko_loadTag(marko_web_block_template);
25
+
26
+ function render(input, out, __component, component, state) {
27
+ var data = input;
28
+
29
+ const { perPage, totalCount, path } = input;
30
+
31
+ const asRels = defaultValue(input.asRels, false);
32
+
33
+ const { htmlSitemapPagination: p } = out.global;
34
+
35
+ const totalPages = p.totalPages({ perPage, totalCount });
36
+
37
+ const nextPage = p.nextPage({ perPage, totalCount });
38
+
39
+ const prevPage = p.prevPage();
40
+
41
+ const nextQuery = new URLSearchParams({ ...input.query, page: nextPage });
42
+
43
+ const prevQuery = new URLSearchParams({ ...input.query, page: prevPage });
44
+
45
+ const nextHref = `/${cleanPath(path)}?${nextQuery}`;
46
+
47
+ const prevHref = `/${cleanPath(path)}?${prevQuery}`;
48
+
49
+ const blockName = "pagination-controls";
50
+
51
+ if (totalCount) {
52
+ if (asRels) {
53
+ if (prevPage) {
54
+ out.w("<link rel=\"prev\"" +
55
+ marko_attr("href", prevHref) +
56
+ ">");
57
+ }
58
+
59
+ if (nextPage) {
60
+ out.w("<link rel=\"next\"" +
61
+ marko_attr("href", nextHref) +
62
+ ">");
63
+ }
64
+ } else {
65
+ marko_web_block_tag({
66
+ name: blockName,
67
+ tag: "div",
68
+ class: input.class,
69
+ renderBody: function(out) {
70
+ if (prevPage) {
71
+ marko_web_link_tag({
72
+ class: ("btn btn-primary " + blockName) + "__prev",
73
+ href: prevHref,
74
+ renderBody: function(out) {
75
+ out.w("Previous Page");
76
+ }
77
+ }, out, __component, "3");
78
+ }
79
+
80
+ marko_web_element_tag({
81
+ name: "pages",
82
+ tag: "div",
83
+ blockName: blockName,
84
+ renderBody: function(out) {
85
+ out.w("Page " +
86
+ marko_escapeXml(p.page) +
87
+ " of " +
88
+ marko_escapeXml(totalPages));
89
+ }
90
+ }, out, __component, "4");
91
+
92
+ if (nextPage) {
93
+ marko_web_link_tag({
94
+ class: ("btn btn-primary " + blockName) + "__next",
95
+ href: nextHref,
96
+ renderBody: function(out) {
97
+ out.w("Next Page");
98
+ }
99
+ }, out, __component, "5");
100
+ }
101
+ }
102
+ }, out, __component, "2");
103
+ }
104
+ }
105
+ }
106
+
107
+ marko_template._ = marko_renderer(render, {
108
+ d_: true,
109
+ e_: marko_componentType
110
+ });
111
+
112
+ marko_template.meta = {
113
+ id: "/@mindful-web/marko-web-html-sitemap$1.0.0/components/pagination-controls.marko",
114
+ tags: [
115
+ "@mindful-web/marko-web/components/element/link.marko",
116
+ "@mindful-web/marko-web/components/element/index.marko",
117
+ "@mindful-web/marko-web/components/element/block.marko"
118
+ ]
119
+ };
@@ -0,0 +1,27 @@
1
+ import gql from "graphql-tag";
2
+ import { getAsObject } from "@mindful-web/object-path";
3
+
4
+ $ const { apollo } = out.global;
5
+
6
+ $ const params = { ...getAsObject(input, "params") };
7
+ $ delete params.queryFragment;
8
+
9
+ $ const optionsMap = {
10
+ "all-published-content": {
11
+ query: gql`
12
+ query AllPublishedContentCount($input: AllPublishedContentQueryInput!) {
13
+ result: allPublishedContent(input: $input) {
14
+ totalCount
15
+ }
16
+ }
17
+ `,
18
+ variables: { input: params },
19
+ }
20
+ };
21
+ $ const options = optionsMap[input.name];
22
+ $ if (!options) throw new Error(`No query options have been defined for ${input.name}`);
23
+
24
+ <marko-web-resolve|{ resolved }| promise=apollo.query(options)>
25
+ $ const { data } = resolved;
26
+ <${input.renderBody} total-count=data.result.totalCount />
27
+ </marko-web-resolve>
@@ -0,0 +1,68 @@
1
+ // Compiled using marko@4.20.2 - DO NOT EDIT
2
+ "use strict";
3
+
4
+ var marko_template = module.exports = require("marko/dist/html").t(__filename),
5
+ marko_componentType = "/@mindful-web/marko-web-html-sitemap$1.0.0/components/query-total-count.marko",
6
+ marko_component = require("./query-total-count.marko"),
7
+ marko_renderer = require("marko/dist/runtime/components/renderer"),
8
+ module_gql = require("graphql-tag"),
9
+ gql = module_gql.default || module_gql,
10
+ module_objectPath_module = require("@mindful-web/object-path"),
11
+ objectPath_module = module_objectPath_module.default || module_objectPath_module,
12
+ getAsObject = module_objectPath_module.getAsObject,
13
+ marko_dynamicTag = require("marko/dist/runtime/helpers/dynamic-tag"),
14
+ marko_web_resolve_template = require("@mindful-web/marko-core/components/resolve.marko"),
15
+ marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
16
+ marko_web_resolve_tag = marko_loadTag(marko_web_resolve_template);
17
+
18
+ function render(input, out, __component, component, state) {
19
+ var data = input;
20
+
21
+ const { apollo } = out.global;
22
+
23
+ const params = { ...getAsObject(input, "params") };
24
+
25
+ delete params.queryFragment;
26
+
27
+ const optionsMap = {
28
+ "all-published-content": {
29
+ query: gql`
30
+ query AllPublishedContentCount($input: AllPublishedContentQueryInput!) {
31
+ result: allPublishedContent(input: $input) {
32
+ totalCount
33
+ }
34
+ }
35
+ `,
36
+ variables: { input: params },
37
+ }
38
+ };
39
+
40
+ const options = optionsMap[input.name];
41
+
42
+ if (!options) throw new Error(`No query options have been defined for ${input.name}`);
43
+
44
+ marko_web_resolve_tag({
45
+ promise: apollo.query(options),
46
+ renderBody: function(out, { resolved }) {
47
+ const { data } = resolved;
48
+
49
+ marko_dynamicTag(out, input.renderBody, function() {
50
+ return {
51
+ "total-count": data.result.totalCount
52
+ };
53
+ }, null, null, null, __component, "1");
54
+ }
55
+ }, out, __component, "0");
56
+ }
57
+
58
+ marko_template._ = marko_renderer(render, {
59
+ e_: marko_componentType
60
+ }, marko_component);
61
+
62
+ marko_template.meta = {
63
+ id: "/@mindful-web/marko-web-html-sitemap$1.0.0/components/query-total-count.marko",
64
+ component: "./query-total-count.marko",
65
+ tags: [
66
+ "@mindful-web/marko-core/components/resolve.marko"
67
+ ]
68
+ };
@@ -0,0 +1,13 @@
1
+ const gql = require('graphql-tag');
2
+
3
+ module.exports = gql`
4
+ fragment SitemapPublishedContentFragment on Content {
5
+ id
6
+ published
7
+ shortName
8
+ siteContext {
9
+ path
10
+ }
11
+ }
12
+
13
+ `;
package/marko.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "taglib-imports": [
3
+ "./components/marko.json"
4
+ ]
5
+ }
@@ -0,0 +1,24 @@
1
+ module.exports = ({ param = 'page' } = {}) => (req, res, next) => {
2
+ const page = parseInt(req.query[param], 10) || 1;
3
+
4
+ const totalPages = ({ perPage, totalCount }) => Math.ceil(totalCount / perPage);
5
+
6
+ res.locals.htmlSitemapPagination = {
7
+ page,
8
+ skip: ({ skip = 0, perPage } = {}) => {
9
+ if (page < 1) return skip;
10
+ return (perPage * (page - 1)) + skip;
11
+ },
12
+ totalPages,
13
+ nextPage: ({ perPage, totalCount }) => {
14
+ const total = totalPages({ perPage, totalCount });
15
+ if (page < total) return page + 1;
16
+ return null;
17
+ },
18
+ prevPage: () => {
19
+ if (page > 1) return page - 1;
20
+ return null;
21
+ },
22
+ };
23
+ next();
24
+ };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@mindful-web/marko-web-html-sitemap",
3
+ "version": "1.0.0",
4
+ "author": "Brian Miller <brian@parameter1.com>",
5
+ "license": "MIT",
6
+ "repository": "https://github.com/parameter1/mindful-web/tree/main/packages/marko-web-html-sitemap",
7
+ "scripts": {
8
+ "lint:fix": "yarn lint --fix",
9
+ "lint": "eslint --ext .js --ext .vue --max-warnings 5 --ignore-path ../../.eslintignore ./",
10
+ "compile": "mindful-web-marko-compile compile",
11
+ "prepublish": "yarn compile --silent",
12
+ "test": "yarn compile --no-clean && yarn lint"
13
+ },
14
+ "dependencies": {
15
+ "@mindful-web/dayjs": "^1.0.0",
16
+ "@mindful-web/object-path": "^1.0.0",
17
+ "@mindful-web/utils": "^1.0.0",
18
+ "graphql": "^14.5.4",
19
+ "graphql-tag": "^2.12.6"
20
+ },
21
+ "peerDependencies": {
22
+ "@mindful-web/marko-core": "^0.0.0",
23
+ "@mindful-web/marko-web": "^0.0.0"
24
+ },
25
+ "gitHead": "0b77cab713eb5841202bb86c7119949866bc68b5"
26
+ }
@@ -0,0 +1,151 @@
1
+ const { getAsArray } = require('@mindful-web/object-path');
2
+ const gql = require('graphql-tag');
3
+ const { asyncRoute } = require('@mindful-web/utils');
4
+ const dayjs = require('@mindful-web/dayjs');
5
+ const dateListTemplate = require('../templates/date-list');
6
+ const dayTemplate = require('../templates/day');
7
+
8
+ const FORMAT = 'YYYY-MM-DD';
9
+ const dateNotFound = () => {
10
+ const error = new Error('The requested date was not found.');
11
+ error.statusCode = 404;
12
+ return error;
13
+ };
14
+ const invalidDate = () => {
15
+ const error = new Error('The requested date is invalid.');
16
+ error.statusCode = 400;
17
+ return error;
18
+ };
19
+
20
+ const getTwoCharNum = (number) => number.toLocaleString('en-US', { minimumIntegerDigits: 2, useGrouping: false });
21
+
22
+ const ALL_PUBLISHED_CONTENT_DATES = gql`
23
+ query AllPublishedContentDates($input: AllPublishedContentDatesQueryInput = {}) {
24
+ allPublishedContentDates(input: $input) {
25
+ id,
26
+ year,
27
+ month,
28
+ day,
29
+ count
30
+ }
31
+ }
32
+ `;
33
+
34
+ module.exports = (app, { mountPoint } = { mountPoint: '/site-map' }) => {
35
+ app.get(`${mountPoint}/:year(\\d{4})/:month(\\d{2})/:day(\\d{2})`, asyncRoute(async (req, res) => {
36
+ const { year, month, day } = req.params;
37
+
38
+ // Validate date
39
+ const dateString = `${year}-${month}-${day}`;
40
+ const date = dayjs(dateString, FORMAT);
41
+ if (!date.isValid()) throw invalidDate();
42
+ const now = dayjs().endOf('day');
43
+ if (date > now) throw dateNotFound();
44
+
45
+ // Set page data
46
+ const ending = date.endOf('day');
47
+ const after = date.startOf('day');
48
+ const displayMonth = date.format('MMMM');
49
+ return res.marko(
50
+ dayTemplate,
51
+ {
52
+ ending,
53
+ after,
54
+ year,
55
+ month: displayMonth,
56
+ day,
57
+ mountPoint,
58
+ },
59
+ );
60
+ }));
61
+
62
+ app.get(`${mountPoint}/:year(\\d{4})/:month(\\d{2})`, asyncRoute(async (req, res) => {
63
+ const { year, month } = req.params;
64
+ const startOfMonth = dayjs(`${year}-${month}-01`, FORMAT);
65
+ if (!startOfMonth.isValid()) throw invalidDate();
66
+ const endOfMonth = startOfMonth.clone().endOf('month');
67
+ const now = dayjs().endOf('day');
68
+ const after = startOfMonth.format(FORMAT);
69
+ if (startOfMonth > now) throw dateNotFound();
70
+ const before = (endOfMonth > now ? now : endOfMonth).format(FORMAT);
71
+ const input = {
72
+ before,
73
+ after,
74
+ format: 'days',
75
+ };
76
+ const variables = { input };
77
+ const { data } = await req.apollo.query({ query: ALL_PUBLISHED_CONTENT_DATES, variables });
78
+ const alias = `${mountPoint}/${year}/${getTwoCharNum(month)}`;
79
+ const nodes = getAsArray(data, 'allPublishedContentDates').map((node) => ({
80
+ ...node,
81
+ alias: `${alias}/${getTwoCharNum(node.day)}`,
82
+ }));
83
+ return res.marko(
84
+ dateListTemplate,
85
+ {
86
+ nodes,
87
+ year,
88
+ month: startOfMonth.format('MMMM'),
89
+ displayType: 'day',
90
+ mountPoint,
91
+ },
92
+ );
93
+ }));
94
+
95
+ app.get(`${mountPoint}/:year(\\d{4})`, asyncRoute(async (req, res) => {
96
+ const { year } = req.params;
97
+ const now = dayjs().endOf('day');
98
+ if (year > now.format('year')) throw dateNotFound();
99
+ const nowFormatted = now.format(FORMAT);
100
+ const end = `${year}-12-31`;
101
+ const after = `${year}-01-01`;
102
+ const before = nowFormatted < end ? nowFormatted : end;
103
+ const input = {
104
+ before,
105
+ after,
106
+ format: 'months',
107
+ };
108
+ const variables = { input };
109
+ const { data } = await req.apollo.query({ query: ALL_PUBLISHED_CONTENT_DATES, variables });
110
+ const alias = `${mountPoint}/${year}`;
111
+ const nodes = getAsArray(data, 'allPublishedContentDates').map((node) => ({
112
+ ...node,
113
+ alias: `${alias}/${getTwoCharNum(node.month)}`,
114
+ }));
115
+ return res.marko(
116
+ dateListTemplate,
117
+ {
118
+ nodes,
119
+ year,
120
+ displayType: 'month',
121
+ mountPoint,
122
+ },
123
+ );
124
+ }));
125
+
126
+ app.get(`${mountPoint}`, asyncRoute(async (req, res) => {
127
+ const now = dayjs().endOf('day');
128
+ const year = dayjs().format('YYYY');
129
+ const nowFormatted = now.format(FORMAT);
130
+ const end = `${year}-12-31`;
131
+ const before = nowFormatted < end ? nowFormatted : end;
132
+ const input = {
133
+ before,
134
+ format: 'years',
135
+ };
136
+ const variables = { input };
137
+ const { data } = await req.apollo.query({ query: ALL_PUBLISHED_CONTENT_DATES, variables });
138
+ const nodes = getAsArray(data, 'allPublishedContentDates').map((node) => ({
139
+ ...node,
140
+ alias: `${mountPoint}/${node.year}`,
141
+ }));
142
+ return res.marko(
143
+ dateListTemplate,
144
+ {
145
+ nodes,
146
+ displayType: 'year',
147
+ mountPoint,
148
+ },
149
+ );
150
+ }));
151
+ };
@@ -0,0 +1,76 @@
1
+ $primary: #000 !default;
2
+ .sitemap {
3
+ .breadcrumb {
4
+ font-size: 1.5rem;
5
+ background: transparent;
6
+ }
7
+ .page-wrapper {
8
+ &__title {
9
+ padding-top: 1.5rem;
10
+ padding-bottom: .5rem;
11
+ margin: 0;
12
+ border-bottom: solid 2px $primary;
13
+ }
14
+ &__description {
15
+ padding-top: .75rem;
16
+ }
17
+ }
18
+ .node-list {
19
+ &__node {
20
+ font-size: 1.1rem;
21
+ }
22
+ }
23
+ .pagination-controls {
24
+ padding-top: 1.2rem;
25
+ margin-bottom: 1.5rem;
26
+ }
27
+ .row {
28
+ &__dates {
29
+ padding-right: .5rem;
30
+ padding-left: .5rem;
31
+ margin-bottom: 1.5rem;
32
+ overflow: hidden;
33
+ }
34
+ }
35
+ .col {
36
+ &__date {
37
+ padding: .75rem .5rem;
38
+ margin-top: 1px;
39
+ margin-bottom: -1px;
40
+ font-size: 1.1rem;
41
+ text-align: center;
42
+ border-bottom: 1px solid #ccc;
43
+
44
+ &--year,
45
+ &--day {
46
+ @include media-breakpoint-down(sm) {
47
+ @include make-col(2);
48
+ }
49
+ @include media-breakpoint-up(sm) {
50
+ flex: 0 0 8.3333%;
51
+ max-width: 8.3333%;
52
+ }
53
+ @include media-breakpoint-up(sm) {
54
+ flex: 0 0 8.3333%;
55
+ max-width: 8.3333%;
56
+ }
57
+ @include media-breakpoint-up(md) {
58
+ flex: 0 0 5%;
59
+ max-width: 5%;
60
+ }
61
+ }
62
+ &--year {
63
+ @include media-breakpoint-up(lg) {
64
+ flex: 0 0 5%;
65
+ max-width: 5%;
66
+ }
67
+ }
68
+ &--month {
69
+ @include make-col-ready();
70
+ @include media-breakpoint-up(md) {
71
+ @include make-col(6);
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
@@ -0,0 +1,66 @@
1
+ import dayjs from "@mindful-web/dayjs";
2
+ import { isFunction } from '@mindful-web/utils';
3
+
4
+ $ const { config, i18n } = out.global;
5
+
6
+ $ const {
7
+ nodes,
8
+ displayType,
9
+ month,
10
+ year,
11
+ mountPoint,
12
+ alias,
13
+ } = input;
14
+
15
+ $ const type = "sitemap";
16
+ $ const pageNode = {
17
+ title: `${ isFunction(i18n) ? i18n("Site Map") : "Site Map"}`,
18
+ };
19
+ $ switch (displayType) {
20
+ case "day":
21
+ pageNode.description = `All ${config.siteName()} stories published by days in ${month} ${year}`;
22
+ break;
23
+ case "month":
24
+ pageNode.description = `All ${config.siteName()} stories published by months in ${year}`;
25
+ break;
26
+ default:
27
+ pageNode.description = `All ${config.siteName()} stories published by years`;
28
+ };
29
+ <marko-web-default-page-layout type=type title=pageNode.title description=pageNode.description>
30
+ <@page>
31
+ <marko-web-page-wrapper class="sitemap">
32
+ <@section>
33
+
34
+ <h1 class="page-wrapper__title">
35
+ <if(year)>
36
+ <marko-web-link href=`${mountPoint}/`>
37
+ ${pageNode.title}
38
+ </marko-web-link>
39
+ </if>
40
+ <else>
41
+ ${pageNode.title}
42
+ </else>
43
+ </h1>
44
+ <marko-web-html-sitemap-breadcrumb ...input page-node=pageNode />
45
+ <!-- <div class="page-wrapper__description">${pageNode.description}</div> -->
46
+ <if(nodes)>
47
+ <div class="row row__dates">
48
+ <for|node| of=nodes>
49
+ <div class=`col__date col__date--${displayType}`>
50
+ <marko-web-link href=`${node.alias}` >
51
+ <if(displayType === 'month')>
52
+ $ const d = dayjs(`${node.year}-${node.month}`, "YYYY-M");
53
+ ${d.format("MMMM")}
54
+ </if>
55
+ <else>
56
+ ${node[displayType]}
57
+ </else>
58
+ </marko-web-link>
59
+ </div>
60
+ </for>
61
+ </div>
62
+ </if>
63
+ </@section>
64
+ </marko-web-page-wrapper>
65
+ </@page>
66
+ </marko-web-default-page-layout>
@@ -0,0 +1,143 @@
1
+ // Compiled using marko@4.20.2 - DO NOT EDIT
2
+ "use strict";
3
+
4
+ var marko_template = module.exports = require("marko/dist/html").t(__filename),
5
+ marko_componentType = "/@mindful-web/marko-web-html-sitemap$1.0.0/templates/date-list.marko",
6
+ marko_renderer = require("marko/dist/runtime/components/renderer"),
7
+ module_dayjs = require("@mindful-web/dayjs"),
8
+ dayjs = module_dayjs.default || module_dayjs,
9
+ module_utils_module = require("@mindful-web/utils"),
10
+ utils_module = module_utils_module.default || module_utils_module,
11
+ isFunction = module_utils_module.isFunction,
12
+ helpers_escape_xml = require("marko/dist/runtime/html/helpers/escape-xml"),
13
+ marko_escapeXml = helpers_escape_xml.x,
14
+ marko_web_link_template = require("@mindful-web/marko-web/components/element/link.marko"),
15
+ marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
16
+ marko_web_link_tag = marko_loadTag(marko_web_link_template),
17
+ marko_assign = require("marko/dist/runtime/helpers/assign"),
18
+ marko_web_html_sitemap_breadcrumb_template = require("../components/breadcrumb.marko"),
19
+ marko_web_html_sitemap_breadcrumb_tag = marko_loadTag(marko_web_html_sitemap_breadcrumb_template),
20
+ marko_forOf = require("marko/dist/runtime/helpers/for-of"),
21
+ marko_classAttr = require("marko/dist/runtime/html/helpers/class-attr"),
22
+ marko_web_page_wrapper_template = require("@mindful-web/marko-web/components/page/wrapper.marko"),
23
+ marko_web_page_wrapper_tag = marko_loadTag(marko_web_page_wrapper_template),
24
+ marko_web_default_page_layout_template = require("@mindful-web/marko-web/components/page/layouts/default.marko"),
25
+ marko_web_default_page_layout_tag = marko_loadTag(marko_web_default_page_layout_template);
26
+
27
+ function render(input, out, __component, component, state) {
28
+ var data = input;
29
+
30
+ const { config, i18n } = out.global;
31
+
32
+ const {
33
+ nodes,
34
+ displayType,
35
+ month,
36
+ year,
37
+ mountPoint,
38
+ alias,
39
+ } = input;
40
+
41
+ const type = "sitemap";
42
+
43
+ const pageNode = {
44
+ title: `${ isFunction(i18n) ? i18n("Site Map") : "Site Map"}`,
45
+ };
46
+
47
+ switch (displayType) {
48
+ case "day":
49
+ pageNode.description = `All ${config.siteName()} stories published by days in ${month} ${year}`;
50
+ break;
51
+ case "month":
52
+ pageNode.description = `All ${config.siteName()} stories published by months in ${year}`;
53
+ break;
54
+ default:
55
+ pageNode.description = `All ${config.siteName()} stories published by years`;
56
+ };
57
+
58
+ marko_web_default_page_layout_tag({
59
+ type: type,
60
+ title: pageNode.title,
61
+ description: pageNode.description,
62
+ page: {
63
+ renderBody: function(out) {
64
+ marko_web_page_wrapper_tag({
65
+ blockName: "page-wrapper",
66
+ tag: "div",
67
+ class: "sitemap",
68
+ sections: [
69
+ {
70
+ tag: "div",
71
+ renderBody: function(out) {
72
+ out.w("<h1 class=\"page-wrapper__title\">");
73
+
74
+ if (year) {
75
+ marko_web_link_tag({
76
+ href: mountPoint + "/",
77
+ renderBody: function(out) {
78
+ out.w(marko_escapeXml(pageNode.title));
79
+ }
80
+ }, out, __component, "5");
81
+ } else {
82
+ out.w(marko_escapeXml(pageNode.title));
83
+ }
84
+
85
+ out.w("</h1>");
86
+
87
+ marko_web_html_sitemap_breadcrumb_tag(marko_assign({}, input, {
88
+ pageNode: pageNode
89
+ }), out, __component, "6");
90
+
91
+ if (nodes) {
92
+ out.w("<div class=\"row row__dates\">");
93
+
94
+ var $for$0 = 0;
95
+
96
+ marko_forOf(nodes, function(node) {
97
+ var $keyScope$0 = "[" + (($for$0++) + "]");
98
+
99
+ out.w("<div" +
100
+ marko_classAttr("col__date col__date--" + displayType) +
101
+ ">");
102
+
103
+ marko_web_link_tag({
104
+ href: "" + node.alias,
105
+ renderBody: function(out) {
106
+ if (displayType === "month") {
107
+ const d = dayjs(`${node.year}-${node.month}`, "YYYY-M");
108
+
109
+ out.w(marko_escapeXml(d.format("MMMM")));
110
+ } else {
111
+ out.w(marko_escapeXml(node[displayType]));
112
+ }
113
+ }
114
+ }, out, __component, "9" + $keyScope$0);
115
+
116
+ out.w("</div>");
117
+ });
118
+
119
+ out.w("</div>");
120
+ }
121
+ }
122
+ }
123
+ ]
124
+ }, out, __component, "2");
125
+ }
126
+ }
127
+ }, out, __component, "0");
128
+ }
129
+
130
+ marko_template._ = marko_renderer(render, {
131
+ d_: true,
132
+ e_: marko_componentType
133
+ });
134
+
135
+ marko_template.meta = {
136
+ id: "/@mindful-web/marko-web-html-sitemap$1.0.0/templates/date-list.marko",
137
+ tags: [
138
+ "@mindful-web/marko-web/components/element/link.marko",
139
+ "../components/breadcrumb.marko",
140
+ "@mindful-web/marko-web/components/page/wrapper.marko",
141
+ "@mindful-web/marko-web/components/page/layouts/default.marko"
142
+ ]
143
+ };
@@ -0,0 +1,71 @@
1
+ import queryFragment from "../graphql/fragments/sitemap-published-content";
2
+ import { isFunction } from '@mindful-web/utils';
3
+
4
+ $ const { config, htmlSitemapPagination: p, req, i18n } = out.global;
5
+ $ const {
6
+ ending,
7
+ after,
8
+ year,
9
+ month,
10
+ day,
11
+ mountPoint,
12
+ } = input;
13
+
14
+ $ const perPage = 1000;
15
+ $ const type = "sitemap";
16
+ $ const date = `${month} ${day}, ${year}`;
17
+ $ const pageNode = {
18
+ title: `${ isFunction(i18n) ? i18n("Site Map") : "Site Map"}`,
19
+ description: `All ${config.siteName()} stories published on ${date}`,
20
+ };
21
+ <marko-web-default-page-layout type=type title=pageNode.title description=pageNode.description>
22
+ <@page>
23
+ <marko-web-page-wrapper class="sitemap">
24
+ <@section>
25
+ <h1 class="page-wrapper__title">
26
+ <marko-web-link href=`${mountPoint}/`>
27
+ ${pageNode.title}
28
+ </marko-web-link>
29
+ </h1>
30
+ <marko-web-html-sitemap-breadcrumb ...input page-node=pageNode />
31
+ <marko-web-query|{ nodes }|
32
+ name="all-published-content"
33
+ params={
34
+ requiresIndexed: true,
35
+ publishedAfter: new Date(after.toISOString()),
36
+ since: new Date(ending.toISOString()),
37
+ limit: perPage,
38
+ skip: p.skip({ perPage }),
39
+ queryFragment,
40
+ }
41
+ >
42
+ <marko-web-node-list
43
+ inner-justified=false
44
+ flush-x=true
45
+ modifiers=["published-content-list"]
46
+ >
47
+ <@nodes nodes=nodes>
48
+ <@slot|{ node }|>
49
+ <marko-web-content-short-name obj=node link=true />
50
+ </@slot>
51
+ </@nodes>
52
+ </marko-web-node-list>
53
+ </marko-web-query>
54
+ <marko-web-html-sitemap-query-total-count|{ totalCount }|
55
+ name="all-published-content"
56
+ params={
57
+ requiresIndexed: true,
58
+ after: after.toDate().getTime(),
59
+ since: ending.toDate().getTime(),
60
+ }
61
+ >
62
+ <marko-web-html-sitemap-pagination-controls
63
+ per-page=perPage
64
+ total-count=totalCount
65
+ path=req.path
66
+ />
67
+ </marko-web-html-sitemap-query-total-count>
68
+ </@section>
69
+ </marko-web-page-wrapper>
70
+ </@page>
71
+ </marko-web-default-page-layout>
@@ -0,0 +1,175 @@
1
+ // Compiled using marko@4.20.2 - DO NOT EDIT
2
+ "use strict";
3
+
4
+ var marko_template = module.exports = require("marko/dist/html").t(__filename),
5
+ marko_componentType = "/@mindful-web/marko-web-html-sitemap$1.0.0/templates/day.marko",
6
+ marko_component = require("./day.marko"),
7
+ marko_renderer = require("marko/dist/runtime/components/renderer"),
8
+ module_queryFragment = require("../graphql/fragments/sitemap-published-content"),
9
+ queryFragment = module_queryFragment.default || module_queryFragment,
10
+ module_utils_module = require("@mindful-web/utils"),
11
+ utils_module = module_utils_module.default || module_utils_module,
12
+ isFunction = module_utils_module.isFunction,
13
+ helpers_escape_xml = require("marko/dist/runtime/html/helpers/escape-xml"),
14
+ marko_escapeXml = helpers_escape_xml.x,
15
+ marko_web_link_template = require("@mindful-web/marko-web/components/element/link.marko"),
16
+ marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
17
+ marko_web_link_tag = marko_loadTag(marko_web_link_template),
18
+ marko_assign = require("marko/dist/runtime/helpers/assign"),
19
+ marko_web_html_sitemap_breadcrumb_template = require("../components/breadcrumb.marko"),
20
+ marko_web_html_sitemap_breadcrumb_tag = marko_loadTag(marko_web_html_sitemap_breadcrumb_template),
21
+ marko_web_content_short_name_template = require("@mindful-web/marko-web/components/element/content/short-name.marko"),
22
+ marko_web_content_short_name_tag = marko_loadTag(marko_web_content_short_name_template),
23
+ marko_web_node_list_template = require("@mindful-web/marko-web/components/node-list/index.marko"),
24
+ marko_web_node_list_tag = marko_loadTag(marko_web_node_list_template),
25
+ marko_web_query_template = require("@mindful-web/marko-core/components/queries/index.marko"),
26
+ marko_web_query_tag = marko_loadTag(marko_web_query_template),
27
+ marko_web_html_sitemap_pagination_controls_template = require("../components/pagination-controls.marko"),
28
+ marko_web_html_sitemap_pagination_controls_tag = marko_loadTag(marko_web_html_sitemap_pagination_controls_template),
29
+ marko_web_html_sitemap_query_total_count_template = require("../components/query-total-count.marko"),
30
+ marko_web_html_sitemap_query_total_count_tag = marko_loadTag(marko_web_html_sitemap_query_total_count_template),
31
+ marko_web_page_wrapper_template = require("@mindful-web/marko-web/components/page/wrapper.marko"),
32
+ marko_web_page_wrapper_tag = marko_loadTag(marko_web_page_wrapper_template),
33
+ marko_web_default_page_layout_template = require("@mindful-web/marko-web/components/page/layouts/default.marko"),
34
+ marko_web_default_page_layout_tag = marko_loadTag(marko_web_default_page_layout_template);
35
+
36
+ function render(input, out, __component, component, state) {
37
+ var data = input;
38
+
39
+ const { config, htmlSitemapPagination: p, req, i18n } = out.global;
40
+
41
+ const {
42
+ ending,
43
+ after,
44
+ year,
45
+ month,
46
+ day,
47
+ mountPoint,
48
+ } = input;
49
+
50
+ const perPage = 1000;
51
+
52
+ const type = "sitemap";
53
+
54
+ const date = `${month} ${day}, ${year}`;
55
+
56
+ const pageNode = {
57
+ title: `${ isFunction(i18n) ? i18n("Site Map") : "Site Map"}`,
58
+ description: `All ${config.siteName()} stories published on ${date}`,
59
+ };
60
+
61
+ marko_web_default_page_layout_tag({
62
+ type: type,
63
+ title: pageNode.title,
64
+ description: pageNode.description,
65
+ page: {
66
+ renderBody: function(out) {
67
+ marko_web_page_wrapper_tag({
68
+ blockName: "page-wrapper",
69
+ tag: "div",
70
+ class: "sitemap",
71
+ sections: [
72
+ {
73
+ tag: "div",
74
+ renderBody: function(out) {
75
+ out.w("<h1 class=\"page-wrapper__title\">");
76
+
77
+ marko_web_link_tag({
78
+ href: mountPoint + "/",
79
+ renderBody: function(out) {
80
+ out.w(marko_escapeXml(pageNode.title));
81
+ }
82
+ }, out, __component, "5");
83
+
84
+ out.w("</h1>");
85
+
86
+ marko_web_html_sitemap_breadcrumb_tag(marko_assign({}, input, {
87
+ pageNode: pageNode
88
+ }), out, __component, "6");
89
+
90
+ marko_web_query_tag({
91
+ collapsible: true,
92
+ name: "all-published-content",
93
+ params: {
94
+ requiresIndexed: true,
95
+ publishedAfter: new Date(after.toISOString()),
96
+ since: new Date(ending.toISOString()),
97
+ limit: perPage,
98
+ skip: p.skip({
99
+ perPage: perPage
100
+ }),
101
+ queryFragment: queryFragment
102
+ },
103
+ renderBody: function(out, { nodes }) {
104
+ marko_web_node_list_tag({
105
+ blockName: "node-list",
106
+ tag: "div",
107
+ justified: false,
108
+ innerJustified: false,
109
+ flushX: true,
110
+ flushY: false,
111
+ fullHeight: false,
112
+ collapsible: true,
113
+ modifiers: [
114
+ "published-content-list"
115
+ ],
116
+ nodes: {
117
+ nodes: nodes,
118
+ slots: [
119
+ {
120
+ renderBody: function(out, { node }) {
121
+ marko_web_content_short_name_tag({
122
+ obj: node,
123
+ link: true
124
+ }, out, __component, "11");
125
+ }
126
+ }
127
+ ]
128
+ }
129
+ }, out, __component, "8");
130
+ }
131
+ }, out, __component, "7");
132
+
133
+ marko_web_html_sitemap_query_total_count_tag({
134
+ name: "all-published-content",
135
+ params: {
136
+ requiresIndexed: true,
137
+ after: after.toDate().getTime(),
138
+ since: ending.toDate().getTime()
139
+ },
140
+ renderBody: function(out, { totalCount }) {
141
+ marko_web_html_sitemap_pagination_controls_tag({
142
+ perPage: perPage,
143
+ totalCount: totalCount,
144
+ path: req.path
145
+ }, out, __component, "13");
146
+ }
147
+ }, out, __component, "12");
148
+ }
149
+ }
150
+ ]
151
+ }, out, __component, "2");
152
+ }
153
+ }
154
+ }, out, __component, "0");
155
+ }
156
+
157
+ marko_template._ = marko_renderer(render, {
158
+ e_: marko_componentType
159
+ }, marko_component);
160
+
161
+ marko_template.meta = {
162
+ id: "/@mindful-web/marko-web-html-sitemap$1.0.0/templates/day.marko",
163
+ component: "./day.marko",
164
+ tags: [
165
+ "@mindful-web/marko-web/components/element/link.marko",
166
+ "../components/breadcrumb.marko",
167
+ "@mindful-web/marko-web/components/element/content/short-name.marko",
168
+ "@mindful-web/marko-web/components/node-list/index.marko",
169
+ "@mindful-web/marko-core/components/queries/index.marko",
170
+ "../components/pagination-controls.marko",
171
+ "../components/query-total-count.marko",
172
+ "@mindful-web/marko-web/components/page/wrapper.marko",
173
+ "@mindful-web/marko-web/components/page/layouts/default.marko"
174
+ ]
175
+ };