Skip to content

Commit

Permalink
refactor(date): replace momentjs with dayjs
Browse files Browse the repository at this point in the history
close #25
  • Loading branch information
Octobug committed Jul 7, 2024
1 parent 8f1db35 commit 7e190ca
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ npm run build
npm run preview
```

There are several other npm script commands in the `scripts` part of [`package.json`](../package.json) that you might want to use.
There are several other npm script commands that you might want to use in the `scripts` part of [`package.json`](../package.json).

### Visual Studio Code

Expand Down
8 changes: 4 additions & 4 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"README": {
"cli": "https://github.com/igorshubovych/markdownlint-cli",
"rules": "https://github.com/DavidAnson/markdownlint",
"cli": "https://github.com/DavidAnson/markdownlint-cli2",
"vscode": "https://github.com/DavidAnson/vscode-markdownlint"
},
"MD013": false,
"MD026": false,
"MD033": false
"line-length": false,
"no-inline-html": false,
"no-trailing-punctuation": false
}
6 changes: 3 additions & 3 deletions .vitepress/theme/components/PostElements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<span
v-if="post.datetime"
:class="$style.elementItem"
:tooltip="moment(post.datetime).format('dddd')"
:tooltip="dayjs(post.datetime).format('dddd')"
>
{{ moment(post.datetime).format("LL") }}
{{ dayjs(post.datetime).format("LL") }}
</span>
<Dot
v-if="post.spot"
Expand Down Expand Up @@ -38,7 +38,7 @@
</template>
<script lang="ts" setup>
import moment from "moment-timezone";
import dayjs from "../dayjs";
import { useData, onContentUpdated } from "vitepress";
import { ref } from "vue";
import { data as allPosts } from "../posts.data";
Expand Down
6 changes: 3 additions & 3 deletions .vitepress/theme/components/PostList.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div :class="$style.postList">
<span :class="[$style.date, $style.hack]">
{{ moment(new Date("1970-04-22")).format(dateFormat) }}
{{ dayjs(new Date("1970-04-22")).format(dateFormat) }}
</span>
<div
v-for="post in postList"
Expand All @@ -12,14 +12,14 @@
<span :class="$style.title">{{ post.frontmatter.title }}</span>
</a>
<span :class="$style.date">
{{ moment(post.frontmatter.datetime).format(dateFormat) }}
{{ dayjs(post.frontmatter.datetime).format(dateFormat) }}
</span>
</div>
</div>
</template>

<script lang="ts" setup>
import moment from "moment-timezone";
import dayjs from "../dayjs";
import Post from "../types/post";
defineProps({
Expand Down
5 changes: 3 additions & 2 deletions .vitepress/theme/components/ProfileExtra.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
</template>

<script lang="ts" setup>
import moment from "moment-timezone";
import dayjs from "../dayjs";
import { useData } from "vitepress";
const { theme } = useData();
const { location, timezone } = theme.value;
const nowWithTZ = moment().tz(timezone);
const nowWithTZ = dayjs().tz(timezone);
const now = {
HHmm: nowWithTZ.format("HH:mm"),
UTCZ: nowWithTZ.format("UTC Z")
Expand Down
10 changes: 10 additions & 0 deletions .vitepress/theme/dayjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import dayjs from "dayjs";
import localizedFormat from "dayjs/plugin/localizedFormat";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";

dayjs.extend(localizedFormat);
dayjs.extend(timezone);
dayjs.extend(utc);

export default dayjs;
29 changes: 4 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Octobug's blog.",
"main": "index.js",
"type": "module",
"engines" : {
"node" : ">=18.0.0"
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"dev": "vitepress dev --host",
Expand Down Expand Up @@ -37,6 +37,7 @@
"@types/node": "^20.8.10",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"dayjs": "^1.11.11",
"dotenv": "^16.3.1",
"eslint": "^8.50.0",
"eslint-plugin-vue": "^9.17.0",
Expand All @@ -48,7 +49,6 @@
"markdown-it-mathjax3": "^4.3.2",
"markdownlint-cli": "^0.37.0",
"mermaid": "^10.9.0",
"moment-timezone": "^0.5.43",
"reading-time": "^1.5.0",
"typescript": "^5.2.2",
"vitepress": "^1.1.3",
Expand Down

0 comments on commit 7e190ca

Please sign in to comment.