update to user process script
Some checks failed
Test Build / Build Example Site (push) Has been cancelled
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 158 KiB |
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 106 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB |
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 79 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 71 KiB |
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 89 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 104 KiB |
Before Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
Before Width: | Height: | Size: 73 KiB After Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 82 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 127 KiB |
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 36 KiB |
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
title: "albertolvera.com"
|
||||
tags: [Sito personale]
|
||||
externalUrl: "https://albertolvera.com"
|
||||
weight: 81
|
||||
title: "さばっこ"
|
||||
tags: [Sito personale, Blog]
|
||||
externalUrl: "https://sabac.co"
|
||||
weight: 961
|
||||
showDate: false
|
||||
showAuthor: false
|
||||
showReadingTime: false
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
title: "albertolvera.com"
|
||||
tags: [個人サイト]
|
||||
externalUrl: "https://albertolvera.com"
|
||||
weight: 81
|
||||
title: "さばっこ"
|
||||
tags: [個人サイト, ブログ]
|
||||
externalUrl: "https://sabac.co"
|
||||
weight: 961
|
||||
showDate: false
|
||||
showAuthor: false
|
||||
showReadingTime: false
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
title: "albertolvera.com"
|
||||
tags: [Personal site]
|
||||
externalUrl: "https://albertolvera.com"
|
||||
weight: 81
|
||||
title: "さばっこ"
|
||||
tags: [Personal site,Blog]
|
||||
externalUrl: "https://sabac.co"
|
||||
weight: 961
|
||||
showDate: false
|
||||
showAuthor: false
|
||||
showReadingTime: false
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
title: "albertolvera.com"
|
||||
tags: [个人网站]
|
||||
externalUrl: "https://albertolvera.com"
|
||||
weight: 81
|
||||
title: "さばっこ"
|
||||
tags: [个人网站, 博客]
|
||||
externalUrl: "https://sabac.co"
|
||||
weight: 961
|
||||
showDate: false
|
||||
showAuthor: false
|
||||
showReadingTime: false
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 152 KiB After Width: | Height: | Size: 152 KiB |
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 139 KiB |
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 69 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 176 KiB After Width: | Height: | Size: 175 KiB |
After Width: | Height: | Size: 61 KiB |
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: "Academy Customize"
|
||||
tags: [Sito aziendale]
|
||||
externalUrl: "https://acamize.com/"
|
||||
weight: 951
|
||||
showDate: false
|
||||
showAuthor: false
|
||||
showReadingTime: false
|
||||
showEdit: false
|
||||
showLikes: false
|
||||
showViews: false
|
||||
layoutBackgroundHeaderSpace: false
|
||||
---
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: "Academy Customize"
|
||||
tags: [事業所]
|
||||
externalUrl: "https://acamize.com/"
|
||||
weight: 951
|
||||
showDate: false
|
||||
showAuthor: false
|
||||
showReadingTime: false
|
||||
showEdit: false
|
||||
showLikes: false
|
||||
showViews: false
|
||||
layoutBackgroundHeaderSpace: false
|
||||
---
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
title: "Academy Customize"
|
||||
tags: [Business site]
|
||||
externalUrl: "https://acamize.com/"
|
||||
weight: 951
|
||||
showDate: false
|
||||
showAuthor: false
|
||||
showReadingTime: false
|
||||
showEdit: false
|
||||
showLikes: false
|
||||
showViews: false
|
||||
layoutBackgroundHeaderSpace: false
|
||||
---
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
title: "Academy Customize"
|
||||
tags: [企业网站]
|
||||
externalUrl: "https://acamize.com/"
|
||||
weight: 951
|
||||
showDate: false
|
||||
showAuthor: false
|
||||
showReadingTime: false
|
||||
showEdit: false
|
||||
showLikes: false
|
||||
showViews: false
|
||||
layoutBackgroundHeaderSpace: false
|
||||
---
|
||||
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
@ -64,14 +64,6 @@
|
|||
"College club site"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "albertolvera.com",
|
||||
"url": "https://albertolvera.com",
|
||||
"source": "n/a",
|
||||
"tags": [
|
||||
"Personal site"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "fahru.my.id",
|
||||
"url": "https://www.fahru.my.id",
|
||||
|
|
171
processUsers.js
|
@ -1,5 +1,5 @@
|
|||
const fs = require('fs');
|
||||
const crypto = require("crypto")
|
||||
const crypto = require("crypto")
|
||||
const puppeteer = require("puppeteer");
|
||||
|
||||
const configDir = "./exampleSite/config/_default";
|
||||
|
@ -12,107 +12,114 @@ var targetLangs = []
|
|||
|
||||
const configFiles = fs.readdirSync(configDir);
|
||||
configFiles.forEach(file => {
|
||||
if (file.indexOf("languages.") > -1) {
|
||||
var lang = file.split(".")[1];
|
||||
if (lang != defaultLang) {
|
||||
targetLangs.push(lang);
|
||||
}
|
||||
if (file.indexOf("languages.") > -1) {
|
||||
var lang = file.split(".")[1];
|
||||
if (lang != defaultLang) {
|
||||
targetLangs.push(lang);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const indexFiles = fs.readdirSync(usersFolderPath);
|
||||
for (var i in targetLangs) {
|
||||
var targetFile = '_index.' + targetLangs[i] + '.md';
|
||||
if (indexFiles.indexOf(targetFile) == -1) {
|
||||
fs.copyFileSync(usersFolderPath + '_index.md', usersFolderPath + targetFile);
|
||||
}
|
||||
var targetFile = '_index.' + targetLangs[i] + '.md';
|
||||
if (indexFiles.indexOf(targetFile) == -1) {
|
||||
fs.copyFileSync(usersFolderPath + '_index.md', usersFolderPath + targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
let rawdata = fs.readFileSync(usersFolderPath + 'users.json');
|
||||
let users = JSON.parse(rawdata);
|
||||
let userDict = {}
|
||||
for (var i in users) {
|
||||
userDict[users[i].title.replaceAll("/", "-")] = true;
|
||||
userDict[generateDirName(users[i].url)] = true;
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(usersFolderPath);
|
||||
|
||||
|
||||
for (file in files) {
|
||||
let stats = fs.statSync(usersFolderPath + files[file]);
|
||||
if (files[file] != 'users.json' && files[file].indexOf("_index.") == -1) {
|
||||
if (stats.isDirectory()) {
|
||||
if (!userDict[files[file].replaceAll("/", "-")]) {
|
||||
console.log('deleting: ', files[file]);
|
||||
fs.rmdirSync(usersFolderPath + files[file], { recursive: true, force: true });
|
||||
}
|
||||
} else {
|
||||
console.log('deleting: ', files[file]);
|
||||
fs.unlinkSync(usersFolderPath + files[file]);
|
||||
}
|
||||
let stats = fs.statSync(usersFolderPath + files[file]);
|
||||
if (files[file] != 'users.json' && files[file].indexOf("_index.") == -1) {
|
||||
if (stats.isDirectory()) {
|
||||
if (!userDict[files[file]]) {
|
||||
console.log('deleting: ', files[file]);
|
||||
fs.rmdirSync(usersFolderPath + files[file], { recursive: true, force: true });
|
||||
}
|
||||
} else {
|
||||
console.log('deleting: ', files[file]);
|
||||
fs.unlinkSync(usersFolderPath + files[file]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cache = {};
|
||||
|
||||
function generateDirName(seed) {
|
||||
var hash = crypto.createHash('md5');
|
||||
hash.update(seed);
|
||||
var dir = hash.digest('hex');
|
||||
return dir;
|
||||
}
|
||||
|
||||
async function convert(text, from, to) {
|
||||
var options = {
|
||||
from: from,
|
||||
to: to
|
||||
};
|
||||
if (!cache[to])
|
||||
cache[to] = {};
|
||||
if (cache[to][text])
|
||||
return cache[to][text];
|
||||
var translated_text = await translate(text, options);
|
||||
cache[to][text] = translated_text.text;
|
||||
return translated_text.text;
|
||||
var options = {
|
||||
from: from,
|
||||
to: to
|
||||
};
|
||||
if (!cache[to])
|
||||
cache[to] = {};
|
||||
if (cache[to][text])
|
||||
return cache[to][text];
|
||||
var translated_text = await translate(text, options);
|
||||
cache[to][text] = translated_text.text;
|
||||
return translated_text.text;
|
||||
}
|
||||
|
||||
async function translateFrontMatterTags(block, targetLang, tags) {
|
||||
var array = block.split("\n");
|
||||
var translatedBlock = "";
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i].indexOf(":") > -1) {
|
||||
var elements = array[i].split(":");
|
||||
var newElement = "";
|
||||
if (elements[0].indexOf("tags") != -1) {
|
||||
translatedTags = []
|
||||
for (var j in tags) {
|
||||
var tempTag = await convert(tags[j], defaultLang, targetLang);
|
||||
translatedTags.push(tempTag);
|
||||
}
|
||||
var trasnlatedTagsString = translatedTags.join(", ");
|
||||
newElement = elements[0] + ": [" + trasnlatedTagsString + "]";
|
||||
} else {
|
||||
newElement = array[i];
|
||||
}
|
||||
} else {
|
||||
newElement = array[i];
|
||||
var array = block.split("\n");
|
||||
var translatedBlock = "";
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i].indexOf(":") > -1) {
|
||||
var elements = array[i].split(":");
|
||||
var newElement = "";
|
||||
if (elements[0].indexOf("tags") != -1) {
|
||||
translatedTags = []
|
||||
for (var j in tags) {
|
||||
var tempTag = await convert(tags[j], defaultLang, targetLang);
|
||||
translatedTags.push(tempTag);
|
||||
}
|
||||
translatedBlock += newElement + "\n";
|
||||
var trasnlatedTagsString = translatedTags.join(", ");
|
||||
newElement = elements[0] + ": [" + trasnlatedTagsString + "]";
|
||||
} else {
|
||||
newElement = array[i];
|
||||
}
|
||||
} else {
|
||||
newElement = array[i];
|
||||
}
|
||||
return translatedBlock;
|
||||
translatedBlock += newElement + "\n";
|
||||
}
|
||||
return translatedBlock;
|
||||
}
|
||||
|
||||
puppeteer
|
||||
.launch({
|
||||
defaultViewport: {
|
||||
width: 1280,
|
||||
height: 800,
|
||||
},
|
||||
})
|
||||
.then(async (browser) => {
|
||||
.launch({
|
||||
defaultViewport: {
|
||||
width: 1280,
|
||||
height: 800,
|
||||
},
|
||||
})
|
||||
.then(async (browser) => {
|
||||
|
||||
const page = await browser.newPage();
|
||||
const page = await browser.newPage();
|
||||
|
||||
for (var i in users) {
|
||||
for (var i in users) {
|
||||
|
||||
var userMDFile = "---\n\
|
||||
var userMDFile = "---\n\
|
||||
title: \""+ users[i].title + "\"\n\
|
||||
tags: ["+ users[i].tags + "]\n\
|
||||
externalUrl: \""+ users[i].url + "\"\n\
|
||||
weight: "+ (i+1) +"\n\
|
||||
weight: "+ (i + 1) + "\n\
|
||||
showDate: false\n\
|
||||
showAuthor: false\n\
|
||||
showReadingTime: false\n\
|
||||
|
@ -121,26 +128,22 @@ puppeteer
|
|||
showViews: false\n\
|
||||
layoutBackgroundHeaderSpace: false\n\
|
||||
\r---\n";
|
||||
|
||||
var dir = usersFolderPath + generateDirName(users[i].url);
|
||||
|
||||
//digest the title to create a folder
|
||||
var hash = crypto.createHash('md5');
|
||||
hash.update(users[i].url);
|
||||
var dir = usersFolderPath + hash.digest('hex');
|
||||
|
||||
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
console.log(i, users[i].title);
|
||||
fs.writeFileSync(dir + '/index.md', userMDFile);
|
||||
for (var j in targetLangs) {
|
||||
var content = await translateFrontMatterTags(userMDFile, targetLangs[j], users[i].tags);
|
||||
fs.writeFileSync(dir + '/index.' + targetLangs[j] + '.md', content);
|
||||
}
|
||||
await page.goto(users[i].url);
|
||||
await page.screenshot({ path: dir + "/feature.jpg" });
|
||||
}
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
console.log(i, users[i].title);
|
||||
fs.writeFileSync(dir + '/index.md', userMDFile);
|
||||
for (var j in targetLangs) {
|
||||
var content = await translateFrontMatterTags(userMDFile, targetLangs[j], users[i].tags);
|
||||
fs.writeFileSync(dir + '/index.' + targetLangs[j] + '.md', content);
|
||||
}
|
||||
await page.goto(users[i].url);
|
||||
await page.screenshot({ path: dir + "/feature.jpg" });
|
||||
}
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
await browser.close();
|
||||
|
||||
});
|
||||
});
|