Attention ! Gitlab fournissant maintenant nativement des certificats Let’s Encrypt aux domaines personnalisés des Gitlab Pages, nous avons coupé notre service qui le faisait automatiquement pour vous.

Il est impératif, pour que votre domaine personnalisé continue à avoir un certificat Let’s Encrypt à jour, d’activer la fonctionnalité native dans les paramètres de votre projet. Cette activation remplacera votre certificat actuel par un nouveau certificat Let’s Encrypt géré par Gitlab.

Voir les détails sur https://docs.framasoft.org/fr/gitlab/gitlab-pages-le.html

Commit ce28848d authored by Christophe Benz's avatar Christophe Benz

Use prettier, read locale from OS, customize template

parent bd9b8abe
{
"$schema": "http://json.schemastore.org/prettierrc",
"semi": false,
"useTabs": false,
"printWidth": 120
}
......@@ -13,5 +13,11 @@ npm install
Given a table schema named `schema.json` (e.g. [this one](https://git.opendatafrance.net/scdl/subventions/blob/master/schema.json)):
```bash
node index.js --locale=fr /path/to/schema.json templates/fr/index.hbs
node index.js /path/to/schema.json
LANG=fr node index.js /path/to/schema.json
LANG=fr node index.js --template template.hbs /path/to/schema.json
```
## Custom templates
- see templates/fr/partials/fieldsAsTable.hbs
const fs = require("fs");
const path = require("path");
const argv = require("minimist")(process.argv.slice(2));
const areIntlLocalesSupported = require("intl-locales-supported");
const handlebars = require("handlebars");
const { get } = require("lodash");
const { Schema } = require("tableschema");
const translations = require("./translations.json");
const fs = require("fs")
const path = require("path")
const argv = require("minimist")(process.argv.slice(2))
const areIntlLocalesSupported = require("intl-locales-supported")
const handlebars = require("handlebars")
const osLocale = require("os-locale")
const { get } = require("lodash")
const { Schema } = require("tableschema")
const translations = require("./translations.json")
function isDir(dirPath) {
return fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory()
}
// Load handlebars-helpers.
require("handlebars-helpers")({ handlebars });
require("handlebars-helpers")({ handlebars })
function setupIntlPolyfill(localesMyAppSupports) {
if (global.Intl) {
......@@ -17,75 +22,81 @@ function setupIntlPolyfill(localesMyAppSupports) {
if (!areIntlLocalesSupported(localesMyAppSupports)) {
// `Intl` exists, but it doesn't have the data we need, so load the
// polyfill and patch the constructors we need with the polyfill's.
var IntlPolyfill = require("intl");
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
var IntlPolyfill = require("intl")
Intl.NumberFormat = IntlPolyfill.NumberFormat
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat
}
} else {
// No `Intl`, so use and load the polyfill.
global.Intl = require("intl");
global.Intl = require("intl")
}
}
const defaultLocale = "en-US";
const locale = argv.locale || defaultLocale;
setupIntlPolyfill([locale]);
const locale = osLocale.sync().replace("_", "-")
setupIntlPolyfill([locale])
// Load handlebars-intl after applying Intl polyfill.
const HandlebarsIntl = require("handlebars-intl");
HandlebarsIntl.registerWith(handlebars);
const HandlebarsIntl = require("handlebars-intl")
HandlebarsIntl.registerWith(handlebars)
function transformField(field) {
const format = get(
translations.format,
`${locale}.${field.format}`,
field.format
);
const type = get(translations.type, `${locale}.${field.type}`, field.type);
return { ...field, format, type };
const format = get(translations.format, `${locale}.${field.format}`, field.format)
const type = get(translations.type, `${locale}.${field.type}`, field.type)
return { ...field, format, type }
}
function transformSchema(schema, locale) {
const fields = schema.fields.map(transformField);
return { ...schema, fields };
const fields = schema.fields.map(transformField)
return { ...schema, fields }
}
async function main() {
// Process file arguments.
const schemaFilePath = path.resolve(argv._[0]);
const templateFilePath = path.resolve(argv._[1]);
const schemaFilePath = path.resolve(argv._[0])
const defaultTemplateFilePath = path.resolve(__dirname, "templates", "fr", "index.hbs")
const templateFilePath = argv.template ? path.resolve(argv.template) : defaultTemplateFilePath
let schema = await Schema.load(schemaFilePath, { strict: true });
let schema = await Schema.load(schemaFilePath, { strict: true })
let schemaJson = require(schemaFilePath);
let schemaJson = require(schemaFilePath)
schema = { ...schemaJson, ...schema.descriptor };
schema = transformSchema(schema, locale);
schema = { ...schemaJson, ...schema.descriptor }
schema = transformSchema(schema, locale)
const templateSource = fs.readFileSync(templateFilePath).toString();
const templateSource = fs.readFileSync(templateFilePath, "utf8")
// Register partials.
const partialsDir = path.resolve(templateFilePath, "..", "partials");
fs.readdirSync(partialsDir).forEach(partialFileName => {
const partialFilePath = path.resolve(partialsDir, partialFileName);
const partialSource = fs.readFileSync(partialFilePath).toString();
const partialName = path.basename(
partialFilePath,
path.extname(partialFilePath)
);
handlebars.registerPartial(partialName, partialSource);
});
function registerPartials(partialsDir) {
fs.readdirSync(partialsDir).forEach(partialFileName => {
const partialFilePath = path.resolve(partialsDir, partialFileName)
const partialSource = fs.readFileSync(partialFilePath, "utf-8")
const partialName = path.basename(partialFilePath, path.extname(partialFilePath))
handlebars.registerPartial(partialName, partialSource)
})
}
const defaultPartialsDir = path.resolve(defaultTemplateFilePath, "..", "partials")
if (isDir(defaultPartialsDir)) {
registerPartials(defaultPartialsDir)
}
if (argv.template) {
const templatePartialsDir = path.resolve(templateFilePath, "..", "partials")
if (isDir(templatePartialsDir)) {
registerPartials(templatePartialsDir)
}
}
if (argv.partials) {
registerPartials(argv.partials)
}
const template = handlebars.compile(templateSource);
const template = handlebars.compile(templateSource)
const intlData = { locales: locale };
const output = template(schema, { data: { intl: intlData } });
const intlData = { locales: locale }
const output = template(schema, { data: { intl: intlData } })
console.log(output);
console.log(output)
}
main().catch(error => {
console.error(error);
process.exit(1);
});
console.error(error)
process.exit(1)
})
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment