Got rid of moment as a direct dependency.

This commit is contained in:
David Soulayrol 2023-08-21 22:47:46 +02:00
parent bc40b6a47d
commit 0aa8d9171a
8 changed files with 14 additions and 16 deletions

View File

@ -1,7 +1,6 @@
<!DOCTYPE HTML>
{% import "footer.njk" as footer %}
{% if lang == undefined %}{% set lang = 'fr' %}{% endif %}
{% set lang = moment.locale(lang) %}
<html lang="{{ lang }}">
<head>
<title>{{ site.title }} | {{ title }}</title>

View File

@ -6,7 +6,7 @@
<h1>{{ title }}</h1>
<p>{% if date %}
{% if lang == 'en' %}Published:{% else %}Publié le :{% endif %}
<time datetime="{{ moment(date).format() }}">{{ moment(date).format('LL') }}</time>
<time datetime="{{ date.toISOString() }}">{{ date_format(lang, date) }}</time>
{% endif %}</p>
</header>
{{ contents | safe }}

View File

@ -1,8 +1,7 @@
{% extends "gemini.njk" %}{% block content %}# {{ book.title }}
{{ contents | safe }}
({{ comment.size }} signes. Première publication {% if comment.issue %}sur {{ comment.medium | safe }} n°{{ comment.issue }}){% else %}le {{ comment.date.format('LL')}} sur {{ comment.medium | safe }}){% endif %}
({{ comment.size }} signes. Première publication {% if comment.issue %}sur {{ comment.medium | safe }} n°{{ comment.issue }}){% else %}le {{ date_format('fr', comment.date)}} sur {{ comment.medium | safe }}){% endif %}
{% if comment.source %}=> {{ comment.source }} Document original{% endif %}
=> {{ filepath(comment.medium, ['/chroniques']) }} Toutes les chroniques sur {{ comment.medium | safe }}

1
package-lock.json generated
View File

@ -30,7 +30,6 @@
"metalsmith-groff": "^0.3.0",
"metalsmith-rename": "^1.0.0",
"metalsmith-sitemap": "^1.2.2",
"moment": "^2.29.1",
"nodemon": "^2.0.12",
"rimraf": "^3.0.2",
"slug": "^8.0.0",

View File

@ -40,7 +40,6 @@
"metalsmith-groff": "^0.3.0",
"metalsmith-rename": "^1.0.0",
"metalsmith-sitemap": "^1.2.2",
"moment": "^2.29.1",
"nodemon": "^2.0.12",
"rimraf": "^3.0.2",
"slug": "^8.0.0",

View File

@ -1,5 +1,4 @@
const debug = require('debug')('metalsmith-gemini:comments')
const moment = require('moment')
module.exports = plugins
@ -35,7 +34,7 @@ function plugins (helpers) {
body += '=> /' + entry.filename + ' ' + entry.book.title + ', ' + entry.book.author
if (index === entry.comment.medium) {
body += ' (' + entry.comment.date.year() + ')\n'
body += ' (' + entry.comment.date.getFullYear() + ')\n'
} else {
body += ' (sur ' + entry.comment.medium + ')\n'
body += entry.comment.excerpt
@ -74,7 +73,7 @@ function plugins (helpers) {
const data = files[filename]
if (data.comment !== undefined) {
data.comment.date = moment(data.comment.date)
data.comment.date = new Date(data.comment.date)
data.comment.excerpt = buildExcerpt(data.contents.toString())
data.comment.size = data.contents.length
data.layout = 'gemini-comment.njk'
@ -106,7 +105,7 @@ function plugins (helpers) {
})
body += '\n## Par année\n\n'
Object.keys(sortedComments(metalsmith, (c) => c.date.year())).forEach((year) => {
Object.keys(sortedComments(metalsmith, (c) => c.date.getFullYear())).forEach((year) => {
body += '=> /chroniques/' + year + ' ' + year + '\n'
})
@ -124,7 +123,7 @@ function plugins (helpers) {
},
yearIndexes: function (files, metalsmith, done) {
Object.entries(sortedComments(metalsmith, (c) => c.date.year())).forEach(([year, comments]) => {
Object.entries(sortedComments(metalsmith, (c) => c.date.getFullYear())).forEach(([year, comments]) => {
helpers.createFile(files, helpers.filepath('index', ['chroniques', year]), createCommentsIndex(year, comments))
})

View File

@ -2,7 +2,6 @@ const comments = require('./metalsmith-gemini-comments.js')
const config = require('./config.js')
const Metalsmith = require('metalsmith')
const layouts = require('@metalsmith/layouts')
const moment = require('moment')
const path = require('path')
const readings = require('./metalsmith-gemini-readings.js')
const slug = require('slug')
@ -10,8 +9,6 @@ const statistics = require('./metalsmith-statistics-plugin')
const __PROD__ = process.env.NODE_ENV === 'production'
moment.locale('fr')
function filepath (filename, segments) {
const name = slug(filename, { mode: 'rfc3986' }) + '.gemini'
return path.join.apply(null, (segments || ['./']).concat([name]))
@ -42,6 +39,10 @@ const readingsGenerator = readings(helpers)
module.exports = new Metalsmith(config.paths.projectRoot)
.clean(__PROD__)
.metadata({
date_format: function (lang, date) {
const options = { dateStyle: 'long' }
return Intl.DateTimeFormat(lang, options).format(date)
},
filepath
})
.source(config.paths.geminiSource)

View File

@ -5,7 +5,6 @@ const groff = require('metalsmith-groff')
const layouts = require('@metalsmith/layouts')
const Metalsmith = require('metalsmith')
const markdown = require('@metalsmith/markdown')
const moment = require('moment')
const rename = require('metalsmith-rename')
const permalinks = require('@metalsmith/permalinks')
const sitemap = require('metalsmith-sitemap')
@ -17,7 +16,10 @@ const __PROD__ = process.env.NODE_ENV === 'production'
module.exports = new Metalsmith(config.paths.projectRoot)
.clean(__PROD__)
.metadata({
moment,
date_format: function (lang, date) {
const options = { dateStyle: 'long' }
return Intl.DateTimeFormat(lang, options).format(date)
},
remove_diatrics: function (e) { return slug(e, { mode: 'rfc3986' }) },
site: {
title: 'David Soulayrol'