hematite 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 893f10d4430904f93e1c546b2906340491a3ed429dffec87e0e3f9633c312e86
4
- data.tar.gz: fac3b2e1aab02fcf932f49bbc04d5ba89ee9e3b81c6f6a25b5fbb5381d1363f6
3
+ metadata.gz: f4b8f5537d27e5ffbcf75f2f7025cf8fb1aad2bb525e95fb6987e75e591313fa
4
+ data.tar.gz: 32705249f519772c0813700e2fe0b3e42bae9685df8a3b8e46c6fdaf8f9f800e
5
5
  SHA512:
6
- metadata.gz: c2de98b2f254eb5349571abeb295e1e640f9efcdd9a193414249d099b4ac463470bcbe1f51eb621c3d139a6c9d1ffb9ca5694f7ad6749d3b981e67de637d420b
7
- data.tar.gz: 7d802505e816146b412af056db60a8a9dc82c312f7015181e036d440f6624bce662b99de84616a1a6f18fa324199b9aa251146bf649c1e49947844072c3d8f66
6
+ metadata.gz: a80d098018413e4ed3aaa77f4ee81b381a36ac8388bb8b7939c4543ebb89f67db4fcc6eb498c9a3e19d593be8a5ad2a7dd3dddee35a0234f11734c2143883754
7
+ data.tar.gz: bd2c7f93936327e295a666056f26b83059c4af507242e6cb367d6bb312a2fe9d20714ee723ada04735b41f44f4cf76ee584b4c1c151477ef214552f2943e4fb4
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
 
@@ -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/_sass/_calendar.scss CHANGED
@@ -58,6 +58,6 @@
58
58
  }
59
59
 
60
60
  &.today {
61
- box-shadow: inset 1px -2px 3px var(--shadow-color-light);
61
+ box-shadow: inset 1px -1px 5px var(--shadow-color-light);
62
62
  }
63
63
  }
@@ -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
- console.log("Parsing", text);
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 new Date(text);
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,14 +26,28 @@ function getCalendarData(elem, formatElemLabels) {
26
26
  for (const child of elem.children) {
27
27
  let tagName = child.tagName.toLowerCase();
28
28
 
29
- if (tagName == DATE_SPEC_ELEM_TAG) {
30
- // Remove '-rd' and '-th' suffixes.
29
+ if (tagName == dateHeaderTag) {
30
+ let errored = false;
31
+
31
32
  try {
32
33
  lastDate = DateUtil.parse(child.innerText);
33
- lastHeaderId = child.getAttribute("id");
34
+ if (isNaN(lastDate)) {
35
+ errored = true;
36
+ } else {
37
+ lastHeaderId = child.getAttribute("id");
38
+
39
+ if (lastHeaderId == null && formatElemLabels) {
40
+ lastHeaderId = escape(child.innerText);
41
+ child.setAttribute("id", lastHeaderId);
42
+ }
43
+ }
34
44
  }
35
45
  catch (e) {
36
- child.innerText = stringLookup(`invalid_date`, dateText);
46
+ errored = true;
47
+ }
48
+
49
+ if (errored) {
50
+ child.innerText = stringLookup(`invalid_date`, child.innerText);
37
51
  lastDate = null;
38
52
  }
39
53
  }
@@ -408,8 +422,8 @@ class Calendar {
408
422
  /// Creates a visual calendar, pulling input from [inputElem]
409
423
  /// and writing output to [outputElem]. If [includePosts], all post-formatted
410
424
  /// articles are also included.
411
- function calendarSetup(sourceElem, outputElem, calendarTitleElem, includePosts) {
412
- let data = getCalendarData(sourceElem, true);
425
+ function calendarSetup(sourceElem, outputElem, calendarTitleElem, includePosts, dateHeaderTag) {
426
+ let data = getCalendarData(sourceElem, true, dateHeaderTag ?? DATE_SPEC_ELEM_TAG);
413
427
 
414
428
  if (includePosts) {
415
429
  data = addPostData(data);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hematite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Heino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-18 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll