-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit-metadata.js
More file actions
42 lines (39 loc) · 1.22 KB
/
Copy pathedit-metadata.js
File metadata and controls
42 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict'
const utils = require('./utils')
const metadata = require('./metadata')
const initialiseAllMetadata = function () {
utils.foreachRecipe('public/recipes', function (recipePath) {
if (!metadata.metadataExists(recipePath)) {
metadata.initialiseMetadata(recipePath)
}
const ignoreErrors = true
const t = metadata.readMetadataSync(recipePath, ignoreErrors)
if (recipePath.search('Vegan') !== -1) {
const recipeTags = t.tags
if (!recipeTags.includes('vegan')) {
recipeTags.push('vegan')
}
}
if (!t.date) {
// New recipe with no date, write one now
const date = new Date()
t.date = utils.formatDate(date)
}
if (!t.image) {
t.image = utils.readImageFromRecipeSync(recipePath)
}
metadata.writeMetadataSync(recipePath, t)
})
}
if (require.main === module) {
// Clear all of the images
utils.foreachRecipe('public/recipes', function (recipePath) {
if (metadata.metadataExists(recipePath)) {
const ignoreErrors = true
const t = metadata.readMetadataSync(recipePath, ignoreErrors)
t.image = ''
metadata.writeMetadataSync(recipePath, t)
}
})
}
module.exports.initialiseAllMetadata = initialiseAllMetadata