hematite 0.0.5 → 0.0.8
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.
- checksums.yaml +4 -4
- data/_config.yml +5 -0
- data/_layouts/calendar.html +3 -2
- data/assets/js/DateUtil.mjs +41 -3
- data/assets/js/layout/calendar.mjs +19 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca054447d56a7d76f00b864906bce8cc2245ba03d089dca22246060f81142a2e
|
4
|
+
data.tar.gz: ba039823072585771bfcdd113454a3de8353219c935907b3b95ae9fb5e82cbe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d4189cc538c9fbd161458570fdeca378971746f33e9365e6ebe5b8806a754517424b1655cbd32994b206bcabd92440f5e462d89153584ee499cb4ccb5fa507
|
7
|
+
data.tar.gz: ca7eb2a71d1b4d6bc342fb2fec21e0bbd3628f78689f0d6728112b1a85842f26f3d90a51e58951e9a69c5871756a9840fc6d224abd600df3559c7bbbf33d276a
|
data/_config.yml
CHANGED
@@ -27,6 +27,11 @@ hematite:
|
|
27
27
|
# The full year
|
28
28
|
year: numeric
|
29
29
|
|
30
|
+
parsing:
|
31
|
+
# True if the date should be parsed MM/DD/YYYY instead of
|
32
|
+
# DD/MM/YYYY
|
33
|
+
month_first: true
|
34
|
+
|
30
35
|
sidebar:
|
31
36
|
footer_html: 'This page was made with the Hematite Theme. <a href="https://github.com/personalizedrefrigerator/jekyll-hematite-theme">Contribute on GitHub</a>'
|
32
37
|
|
data/_layouts/calendar.html
CHANGED
@@ -21,10 +21,11 @@ layout: default
|
|
21
21
|
null,
|
22
22
|
{% endif %}
|
23
23
|
{% if page.include_posts %}
|
24
|
-
true
|
24
|
+
true,
|
25
25
|
{% else %}
|
26
|
-
false
|
26
|
+
false,
|
27
27
|
{% endif %}
|
28
|
+
{{ page.calendar_date_elem | default: "h1" | jsonify }},
|
28
29
|
);
|
29
30
|
|
30
31
|
// Remove the title if we're not using it — it can mess with
|
data/assets/js/DateUtil.mjs
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
---
|
2
2
|
---
|
3
3
|
|
4
|
+
import { assertEq } from "./assertions.mjs";
|
5
|
+
|
4
6
|
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
5
7
|
const MS_PER_WEEK = MS_PER_DAY * 7;
|
6
8
|
|
@@ -94,12 +96,39 @@ var DateUtil = {
|
|
94
96
|
|
95
97
|
/// Slightly more intelligent date parsing than new Date(string).
|
96
98
|
parse(text) {
|
99
|
+
text = text.trim();
|
100
|
+
|
97
101
|
// Remove -th, -rd, -ero suffexes
|
98
|
-
text = text.replaceAll(/(\d)(?:rd|th|ero)/g,
|
102
|
+
text = text.replaceAll(/(\d)(?:rd|st|th|ero)/g,
|
99
103
|
(fullMatch, group0) => group0);
|
100
|
-
|
104
|
+
let res = new Date(0);
|
105
|
+
|
106
|
+
let shortMatch = text.match(/^(\d+)\/(\d+)\/(\d{2,})$/);
|
107
|
+
|
108
|
+
// DD/MM/YY+ or MM/DD/YY+
|
109
|
+
if (shortMatch) {
|
110
|
+
let year = parseInt(shortMatch[3]);
|
111
|
+
{% if site.hematite.date_format.parsing.month_first %}
|
112
|
+
let month = parseInt(shortMatch[1]);
|
113
|
+
let day = parseInt(shortMatch[2]);
|
114
|
+
{% else %}
|
115
|
+
let month = parseInt(shortMatch[2]);
|
116
|
+
let day = parseInt(shortMatch[1]);
|
117
|
+
{% endif %}
|
118
|
+
|
119
|
+
if (shortMatch[3].length >= 4) {
|
120
|
+
res.setFullYear(year);
|
121
|
+
}
|
122
|
+
else if (shortMatch[3].length == 2){
|
123
|
+
res.setFullYear(2000 + year);
|
124
|
+
}
|
125
|
+
res.setMonth(month - 1, day);
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
res = new Date(text);
|
129
|
+
}
|
101
130
|
|
102
|
-
return
|
131
|
+
return res;
|
103
132
|
},
|
104
133
|
|
105
134
|
/// Returns true iff the given object is a date object.
|
@@ -120,4 +149,13 @@ var DateUtil = {
|
|
120
149
|
},
|
121
150
|
};
|
122
151
|
|
152
|
+
assertEq("Check if new Date() is a date",
|
153
|
+
DateUtil.isDate(new Date()), true);
|
154
|
+
assertEq("Check if dates can be parsed",
|
155
|
+
DateUtil.parse("01/01/22").getFullYear(), 2022);
|
156
|
+
assertEq("Same day test 1",
|
157
|
+
DateUtil.datesAreOnSameDay(DateUtil.parse("01/02/22"), DateUtil.parse("01/02/2022")), true);
|
158
|
+
assertEq("Same day test 2",
|
159
|
+
DateUtil.datesAreOnSameDay(DateUtil.parse("01/01/22"), DateUtil.parse("January 1st, 2022")), true);
|
160
|
+
|
123
161
|
export default DateUtil;
|
@@ -15,8 +15,8 @@ const CALENDAR_DATE_FMT_OPTIONS =
|
|
15
15
|
let nextViewModeSelectorId = 0;
|
16
16
|
|
17
17
|
/// Pull calendar data from [elem]. If [formatElemLabels], apply special calendar markup
|
18
|
-
/// to the contents of [elem], changing [elem].
|
19
|
-
function getCalendarData(elem, formatElemLabels) {
|
18
|
+
/// to the contents of [elem], fix missing ids on headers, etc., changing [elem].
|
19
|
+
function getCalendarData(elem, formatElemLabels, dateHeaderTag) {
|
20
20
|
let result = [];
|
21
21
|
|
22
22
|
// Last date set by a header we've encountered
|
@@ -26,7 +26,7 @@ function getCalendarData(elem, formatElemLabels) {
|
|
26
26
|
for (const child of elem.children) {
|
27
27
|
let tagName = child.tagName.toLowerCase();
|
28
28
|
|
29
|
-
if (tagName ==
|
29
|
+
if (tagName == dateHeaderTag) {
|
30
30
|
let errored = false;
|
31
31
|
|
32
32
|
try {
|
@@ -35,6 +35,11 @@ function getCalendarData(elem, formatElemLabels) {
|
|
35
35
|
errored = true;
|
36
36
|
} else {
|
37
37
|
lastHeaderId = child.getAttribute("id");
|
38
|
+
|
39
|
+
if (lastHeaderId == null && formatElemLabels) {
|
40
|
+
lastHeaderId = escape(child.innerText);
|
41
|
+
child.setAttribute("id", lastHeaderId);
|
42
|
+
}
|
38
43
|
}
|
39
44
|
}
|
40
45
|
catch (e) {
|
@@ -86,8 +91,7 @@ function getCalendarData(elem, formatElemLabels) {
|
|
86
91
|
}
|
87
92
|
|
88
93
|
result.sort(AgendaItem.compare);
|
89
|
-
|
90
|
-
return result;
|
94
|
+
return joinDuplicateData(result);
|
91
95
|
}
|
92
96
|
|
93
97
|
/// Adds post data to the given calendar data item.
|
@@ -122,6 +126,14 @@ function addPostData(data) {
|
|
122
126
|
|
123
127
|
data.sort(AgendaItem.compare);
|
124
128
|
|
129
|
+
|
130
|
+
return joinDuplicateData(data);
|
131
|
+
}
|
132
|
+
|
133
|
+
/// Ensures that there is only one entry per date (at most),
|
134
|
+
/// returns an updated version with agenda items moved such that
|
135
|
+
/// this is so.
|
136
|
+
function joinDuplicateData(data) {
|
125
137
|
let newData = [];
|
126
138
|
let currentItem;
|
127
139
|
|
@@ -417,8 +429,8 @@ class Calendar {
|
|
417
429
|
/// Creates a visual calendar, pulling input from [inputElem]
|
418
430
|
/// and writing output to [outputElem]. If [includePosts], all post-formatted
|
419
431
|
/// articles are also included.
|
420
|
-
function calendarSetup(sourceElem, outputElem, calendarTitleElem, includePosts) {
|
421
|
-
let data = getCalendarData(sourceElem, true);
|
432
|
+
function calendarSetup(sourceElem, outputElem, calendarTitleElem, includePosts, dateHeaderTag) {
|
433
|
+
let data = getCalendarData(sourceElem, true, dateHeaderTag ?? DATE_SPEC_ELEM_TAG);
|
422
434
|
|
423
435
|
if (includePosts) {
|
424
436
|
data = addPostData(data);
|