Replacing Moment.js with native JavaScript (#266)

* fix-262

* Replacing Moment.js with native JavaScript
This commit is contained in:
MyGiHu 2020-12-04 16:49:32 +01:00 committed by GitHub
parent 293ab665ca
commit 6925c0248c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 22 deletions

View file

@ -1,11 +0,0 @@
$(document).ready(function() {
const tnode = $("#time")
const update_localtime = function(){
var time = moment()
.tz(tnode.attr("data-time-zone"))
.format(tnode.attr("data-time-format"));
tnode.html(time);
}
update_localtime();
setInterval(update_localtime, 1000);
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -23,7 +23,7 @@ DefaultContentLanguage = "en" # Default language fo
numberOfProjectsToShow = 3 # Maximum number of projects to show on home page. Unset or comment out to show all projects numberOfProjectsToShow = 3 # Maximum number of projects to show on home page. Unset or comment out to show all projects
localTime = true # Show your current local time in contact section localTime = true # Show your current local time in contact section
timeZone = "America/Los_Angeles" # Your timezone as in the TZ* column of this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones timeZone = "America/Los_Angeles" # Your timezone as in the TZ* column of this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
timeFormat = "h:mm A" # https://momentjs.com/docs/#/displaying/format/ timeFormat = "en-US" # Language specific format to use
[params.projects] [params.projects]
useTwoColumns = false # Use a layout with two columns instead of three useTwoColumns = false # Use a layout with two columns instead of three

View file

@ -106,7 +106,7 @@
{{ .Content }} {{ .Content }}
</div> </div>
{{ if .Site.Params.home.localTime }} {{ if .Site.Params.home.localTime }}
<p>{{ i18n "index_currentTime" . }} <span id="time" data-time-zone="{{ .Site.Params.home.timeZone }}" data-time-format="{{ .Site.Params.home.timeFormat }}"></span>.</p> <p>{{ i18n "index_currentTime" . }} <span id="time"></span>.</p>
{{ end }} {{ end }}
{{ with .Site.Params.email }} {{ with .Site.Params.email }}
<h3 class="subtitle is-3 has-text-centered top-pad"> <h3 class="subtitle is-3 has-text-centered top-pad">
@ -132,12 +132,15 @@
{{ partial "js/owlCarousel.html" . }} {{ partial "js/owlCarousel.html" . }}
{{ if .Site.Params.home.localTime }} {{ if .Site.Params.home.localTime }}
{{ $momentjs := resources.Get "vendor/momentjs/moment.min.js" }} <script>
{{ $momentTimezone := resources.Get "vendor/momentjs/moment-timezone.min.js" }} function update_localtime() {
{{ $momentTimezoneWithData := resources.Get "vendor/momentjs/moment-timezone-with-data-2012-2022.min.js" }} const time = new Date().toLocaleTimeString('{{ .Site.Params.home.timeFormat }}', { timeZone: '{{ .Site.Params.home.timeZone }}', timeStyle: 'short' });
{{ $initMomentjs := resources.Get "js/initMoment.js" }} document.getElementById('time').innerHTML = time;
{{ $bundleMoment := slice $momentjs $momentTimezone $momentTimezoneWithData $initMomentjs | resources.Concat "js/bundleMoment.js" | fingerprint }} }
<script src="{{ $bundleMoment.Permalink }}" integrity="{{ $bundleMoment.Data.Integrity }}"></script> update_localtime();
// Updating every second to prevent seconds looking like stood still when timeStyle is ignored.
setInterval(update_localtime, 1000);
</script>
{{ end }} {{ end }}
</body> </body>