diff --git a/internal/web/server/renderer.go b/internal/web/server/renderer.go index 2a6b840..65eaa25 100644 --- a/internal/web/server/renderer.go +++ b/internal/web/server/renderer.go @@ -15,6 +15,7 @@ import ( "strings" "time" + "github.com/dustin/go-humanize" "github.com/labstack/echo/v4" "github.com/rs/zerolog/log" "github.com/thomiceli/opengist/internal/config" @@ -175,6 +176,16 @@ func (s *Server) setFuncMap() { h, _ := strconv.ParseUint(strings.TrimPrefix(hex, "#"), 16, 32) return fmt.Sprintf("%d, %d, %d,", (h>>16)&0xFF, (h>>8)&0xFF, h&0xFF) }, + "humanTimeDiff": func(t int64) string { + return humanize.Time(time.Unix(t, 0)) + }, + "humanTimeDiffStr": func(timestamp string) string { + t, _ := strconv.ParseInt(timestamp, 10, 64) + return humanize.Time(time.Unix(t, 0)) + }, + "humanDate": func(t int64) string { + return time.Unix(t, 0).Format("02/01/2006 15:04") + }, } t := template.Must(template.New("t").Funcs(fm).ParseFS(templates.Files, "*/*.html")) diff --git a/package-lock.json b/package-lock.json index 546d71b..46d9cc8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,6 @@ "autoprefixer": "^10.4.14", "codemirror": "^6.0.1", "cssnano": "^5.1.15", - "dayjs": "^1.11.9", "github-markdown-css": "^5.5.0", "highlight.js": "^11.11.1", "jdenticon": "^3.3.0", @@ -1872,13 +1871,6 @@ "node": ">=8.0.0" } }, - "node_modules/dayjs": { - "version": "1.11.11", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.11.tgz", - "integrity": "sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==", - "dev": true, - "license": "MIT" - }, "node_modules/debug": { "version": "3.2.7", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", diff --git a/package.json b/package.json index 8692362..d4cad62 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "autoprefixer": "^10.4.14", "codemirror": "^6.0.1", "cssnano": "^5.1.15", - "dayjs": "^1.11.9", "github-markdown-css": "^5.5.0", "highlight.js": "^11.11.1", "jdenticon": "^3.3.0", diff --git a/public/main.ts b/public/main.ts index 7fc2167..6dd8163 100644 --- a/public/main.ts +++ b/public/main.ts @@ -1,23 +1,8 @@ import './style.scss'; import './favicon-32.png'; import './opengist.svg'; -import dayjs from 'dayjs'; -import relativeTime from 'dayjs/plugin/relativeTime'; -import 'dayjs/locale/cs'; -import 'dayjs/locale/de'; -import 'dayjs/locale/es'; -import 'dayjs/locale/fr'; -import 'dayjs/locale/hu'; -import 'dayjs/locale/pt'; -import 'dayjs/locale/ru'; -import 'dayjs/locale/zh'; -import localizedFormat from 'dayjs/plugin/localizedFormat'; import jdenticon from 'jdenticon/standalone'; -dayjs.extend(relativeTime); -dayjs.extend(localizedFormat); -dayjs.locale(window.opengist_locale || 'en'); - jdenticon.update("[data-jdenticon-value]") document.addEventListener('DOMContentLoaded', () => { @@ -55,23 +40,13 @@ document.addEventListener('DOMContentLoaded', () => { document.getElementById('user-menu').classList.toggle('hidden'); }) - document.querySelectorAll('.moment-timestamp').forEach((e: HTMLElement) => { - e.title = dayjs.unix(parseInt(e.innerHTML)).format('LLLL'); - e.innerHTML = dayjs.unix(parseInt(e.innerHTML)).fromNow(); - }); - - document.querySelectorAll('.moment-timestamp-date').forEach((e: HTMLElement) => { - e.innerHTML = dayjs.unix(parseInt(e.innerHTML)).format('DD/MM/YYYY HH:mm'); - }); - document.querySelectorAll('form').forEach((form: HTMLFormElement) => { form.onsubmit = () => { form.querySelectorAll('input[type=datetime-local]').forEach((input: HTMLInputElement) => { - console.log(dayjs(input.value).unix()); const hiddenInput = document.createElement('input'); hiddenInput.type = 'hidden'; hiddenInput.name = 'expiredAtUnix' - hiddenInput.value = dayjs(input.value).unix().toString(); + hiddenInput.value = Math.floor(new Date(input.value).getTime() / 1000).toString(); form.appendChild(hiddenInput); }); return true; diff --git a/templates/base/gist_header.html b/templates/base/gist_header.html index 898260b..42d0d95 100644 --- a/templates/base/gist_header.html +++ b/templates/base/gist_header.html @@ -91,7 +91,7 @@ {{ if .gist.Forked }}
{{ .locale.Tr "gist.header.forked-from" }} {{ .gist.Forked.User.Username }}/{{ .gist.Forked.Title }}
{{ end }} -{{ .locale.Tr "gist.header.last-active" }} +
{{ .locale.Tr "gist.header.last-active" }} {{ .gist.UpdatedAt | humanTimeDiff }} {{ if .gist.Private }} • {{ visibilityStr .gist.Private false }} {{ end }}
{{ .gist.Description }}
diff --git a/templates/pages/admin_gists.html b/templates/pages/admin_gists.html index 945d028..01c6923 100644 --- a/templates/pages/admin_gists.html +++ b/templates/pages/admin_gists.html @@ -26,7 +26,7 @@