Skip to content

Commit

Permalink
Merge branch 'pre-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaslanjaka committed Jan 21, 2024
2 parents 9dc6aab + da3aaca commit 4dd9fa6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
bash ./bin/submodule-install
- name: initialize nodejs
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.node-version }}

Expand Down
16 changes: 8 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
"**/node_modules": true
},
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": false
"source.fixAll": "explicit",
"source.organizeImports": "never"
},
"[markdown]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.organizeImports": false
"source.fixAll": "never",
"source.organizeImports": "never"
}
},
"[typescript]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"[javascript]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": false
"source.fixAll": "explicit",
"source.organizeImports": "never"
}
},
"files.eol": "\n",
Expand Down
21 changes: 14 additions & 7 deletions src/parseDateMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ export /**
*/
function moment(
date: momentInstance.MomentInput = new Date(),
format?: string
format?: string //= 'YYYY-MM-DDTHH:mm:ssZ'
) {
try {
let parse = momentInstance(date, format);
const config = getConfig();
if (config.timezone) {
parse = parse.tz(config.timezone || 'UTC');
let parse: momentInstance.Moment = momentInstance(date, format);
// fix ISO date format
const isISO = typeof date === 'string' && date.endsWith('Z');
if (isISO) {
parse = parse.utc();
} else {
const config = getConfig();
if (config.timezone) {
parse = parse.tz(config.timezone || 'UTC');
}
}
return parse;
} catch {
Expand All @@ -28,6 +34,7 @@ function moment(
*/
export const cmoment = moment;
export const customMoment = moment;
export const momentHpp = moment;

/**
* Moment check date is today
Expand All @@ -36,14 +43,14 @@ export const customMoment = moment;
*/
export const isToday = (date: any) => moment(0, 'HH').diff(date, 'days') == 0;

export type DateMapperInput = moment.MomentInput | parseDateMapper;
export type DateMapperInput = momentInstance.MomentInput | parseDateMapper;

/**
* HexoJS date formatter
* * Playground Test {@link https://codepen.io/dimaslanjaka/pen/LYegjaV}
*/
export class parseDateMapper {
data: moment.Moment;
data: momentInstance.Moment;
constructor(date: DateMapperInput) {
const config = getConfig();
if (typeof date == 'string' && date.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions test/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ post_dir: src-posts
root: /
url: https://mysite.com/
permalink: :year/:month/:name.html
timezone: Asia/Jakarta
10 changes: 10 additions & 0 deletions test/parseDateMapper.ISO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
process.cwd = () => __dirname;
if (!process.env.DEBUG) {
process.env.DEBUG =
'hexo-post-parser,hexo-post-parser:*,hexo-post-parser:*:*';
}

import { momentHpp } from '../src/parseDateMapper';

const iso = momentHpp('2011-04-11T10:20:30Z');
console.log(iso.format('YYYY-MM-DDTHH:mm:ssZ'));

0 comments on commit 4dd9fa6

Please sign in to comment.