-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-feed.js
99 lines (86 loc) · 2.74 KB
/
generate-feed.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const { exec } = require("child_process");
const { join } = require("path");
const RSS = require("rss");
let config = require("./config.json")
function getFileModificationDates() {
return new Promise((resolve, reject) => {
// 1.step get file modification timestamps from git
// command taken from https://serverfault.com/questions/401437/how-to-retrieve-the-last-modification-date-of-all-files-in-a-git-repository/1031956#1031956
exec(
'git ls-tree -r --name-only HEAD -z | TZ=UTC xargs -0n1 -I_ git --no-pager log -1 --date=iso-local --format="%ct _" -- _',
{ cwd: join(__dirname, "/db/apps") },
(error, stdout, stderr) => {
if (error) {
reject(error);
}
if (stderr) {
console.error(`git stderr: ${stderr}`);
}
const entries = {};
for (const entry of stdout.split("\n")) {
const [timestamp, filename] = entry.split(" ");
if (filename) entries[filename.split(".")[0]] = timestamp;
}
resolve(entries);
}
);
});
}
/** @typedef {import("./schema").Schema} DataSchema */
/**
*
* @param {DataSchema["apps"]} apps
* @param {DataSchema["categories"]} categories
* @returns
*/
async function generate_feed(apps, categories) {
const dates = await getFileModificationDates();
// console.log({ dates });
let feed = new RSS({
title: config.title,
description: config.description,
site_url: config.site_url, // TODO create store landing page and link to that instead
docs: config.docs,
language: config.language,
pubDate: Date.now()
});
for (const app of apps) {
let description_content = app.description;
description_content += `\n\nVersion: ${app.download.version}`;
description_content += `<img src="${app.icon}" />`;
if (app.screenshots && app.screenshots.length > 0) {
description_content += "Screenshots:\n";
for (const screenshot of app.screenshots) {
description_content += `<img src="${screenshot}" />`;
}
}
feed.item({
title: app.name,
description: description_content,
author: app.author,
categories: app.meta.categories.map(c => categories[c].name),
custom_elements: [
{
maintainer: app.maintainer
},
{
dependencies: app.dependencies
},
{
locales: app.locales
},
{
git_repo: app.git_repo
},
{
tags: app.meta.tags
}
],
date: new Date(dates[app.slug] * 1000),
// url - IDEA -> could lead to a landing page that redirects to app in store or in webstore depending on used device
url: app.download.url
});
}
return feed.xml();
}
module.exports = { generate_feed };