Skip to content

Commit

Permalink
moving to luxon from moment
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray committed Apr 20, 2021
1 parent fad9b3e commit 900d714
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "writr",
"version": "1.5.2",
"version": "1.5.4",
"description": "A Simple to Use Markdown Blog",
"main": "./dist/index",
"types": "./dist/index",
Expand Down Expand Up @@ -47,8 +47,8 @@
"gray-matter": "^4.0.2",
"helper-date": "^1.0.1",
"keyv": "^4.0.3",
"luxon": "^1.26.0",
"markdown-it": "^12.0.6",
"moment": "^2.29.1",
"parse-json": "^5.2.0",
"promisify": "^0.0.3",
"winston": "^3.3.3"
Expand All @@ -60,6 +60,7 @@
"@types/fs-extra": "^9.0.11",
"@types/jest": "^26.0.22",
"@types/keyv": "^3.1.1",
"@types/luxon": "^1.26.4",
"@types/markdown-it": "^12.0.1",
"@types/node": "^14.14.41",
"@types/parse-json": "^4.0.0",
Expand Down
45 changes: 25 additions & 20 deletions src/post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as MarkDownIt from "markdown-it";
import { DateTime } from "luxon";

export class Post {
keywords: Array<string> = [];
Expand All @@ -17,9 +18,14 @@ export class Post {
}

get date(): Date {
let moment = require("moment");
let newDate = moment(this.matter.date).toDate();
return newDate;
if(Object.prototype.toString.call(this.matter.date) !== "[object Date]"){
let newDate = DateTime.fromISO(this.matter.date).toJSDate();
return newDate;

} else {
return this.matter.date;
}

}

get title(): string {
Expand Down Expand Up @@ -154,8 +160,7 @@ export class Post {

parseUrl(url:string): string {

let moment = require("moment");
let date = moment(this.date);
let date = DateTime.fromJSDate(this.date);

//title
let title = this._matter.title.toLowerCase().replace(/[^a-z0-9+]+/gi, " ").trim();
Expand All @@ -174,21 +179,21 @@ export class Post {
url = this.permalink_ordinal;
}

url = url.split(":year").join(date.format("YYYY"));
url = url.split(":short_year").join(date.format("YY"));
url = url.split(":month").join(date.format("MM"));
url = url.split(":i_month").join(date.format("M"));
url = url.split(":short_month").join(date.format("MMM"));
url = url.split(":long_month").join(date.format("MMMM"));
url = url.split(":day").join(date.format("DD"));
url = url.split(":i_day").join(date.format("D"));
url = url.split(":y_day").join(date.format("DDD"));
url = url.split(":short_day").join(date.format("dd"));
url = url.split(":long_day").join(date.format("dddd"));
url = url.split(":week").join(date.format("ww"));
url = url.split(":hour").join(date.format("HH"));
url = url.split(":minute").join(date.format("mm"));
url = url.split(":second").join(date.format("ss"));
url = url.split(":year").join(date.toFormat("yyyy"));
url = url.split(":short_year").join(date.toFormat("yy"));
url = url.split(":month").join(date.toFormat("LL"));
url = url.split(":i_month").join(date.toFormat("L"));
url = url.split(":short_month").join(date.toFormat("LLL"));
url = url.split(":long_month").join(date.toFormat("LLLL"));
url = url.split(":day").join(date.toFormat("dd"));
url = url.split(":i_day").join(date.toFormat("d"));
url = url.split(":y_day").join(date.toFormat("o"));
url = url.split(":short_day").join(date.toFormat("ccc"));
url = url.split(":long_day").join(date.toFormat("cccc"));
url = url.split(":week").join(date.toFormat("W"));
url = url.split(":hour").join(date.toFormat("HH"));
url = url.split(":minute").join(date.toFormat("mm"));
url = url.split(":second").join(date.toFormat("ss"));

url = url.split(":title").join(title);

Expand Down
12 changes: 11 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,11 @@
resolved "https://registry.yarnpkg.com/@types/linkify-it/-/linkify-it-3.0.1.tgz#4d26a9efe3aa2caf829234ec5a39580fc88b6001"
integrity sha512-pQv3Sygwxxh6jYQzXaiyWDAHevJqWtqDUv6t11Sa9CPGiXny66II7Pl6PR8QO5OVysD6HYOkHMeBgIjLnk9SkQ==

"@types/luxon@^1.26.4":
version "1.26.4"
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-1.26.4.tgz#77bbd5a1aa74ca31edff2aee4f8313ea0d93ca5c"
integrity sha512-OIvbVLZQUjyZofqSFpre2VsgvKy0V0JQdRgN0k3H1DTGRdxHiaQjT16+H2gyuhAS9r8B2PQEwrSiqP6/Zka3pQ==

"@types/markdown-it@^12.0.1":
version "12.0.1"
resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-12.0.1.tgz#8391e19fea4796ff863edda55800c7e669beb358"
Expand Down Expand Up @@ -3675,6 +3680,11 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"

luxon@^1.26.0:
version "1.26.0"
resolved "https://registry.yarnpkg.com/luxon/-/luxon-1.26.0.tgz#d3692361fda51473948252061d0f8561df02b578"
integrity sha512-+V5QIQ5f6CDXQpWNICELwjwuHdqeJM1UenlZWx5ujcRMc9venvluCjFb4t5NYLhb6IhkbMVOxzVuOqkgMxee2A==

make-dir@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
Expand Down Expand Up @@ -3806,7 +3816,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

moment@^2.18.1, moment@^2.29.1:
moment@^2.18.1:
version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
Expand Down

0 comments on commit 900d714

Please sign in to comment.