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"
|
title: "さばっこ"
|
||||||
tags: [Sito personale]
|
tags: [Sito personale, Blog]
|
||||||
externalUrl: "https://albertolvera.com"
|
externalUrl: "https://sabac.co"
|
||||||
weight: 81
|
weight: 961
|
||||||
showDate: false
|
showDate: false
|
||||||
showAuthor: false
|
showAuthor: false
|
||||||
showReadingTime: false
|
showReadingTime: false
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
title: "albertolvera.com"
|
title: "さばっこ"
|
||||||
tags: [個人サイト]
|
tags: [個人サイト, ブログ]
|
||||||
externalUrl: "https://albertolvera.com"
|
externalUrl: "https://sabac.co"
|
||||||
weight: 81
|
weight: 961
|
||||||
showDate: false
|
showDate: false
|
||||||
showAuthor: false
|
showAuthor: false
|
||||||
showReadingTime: false
|
showReadingTime: false
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
title: "albertolvera.com"
|
title: "さばっこ"
|
||||||
tags: [Personal site]
|
tags: [Personal site,Blog]
|
||||||
externalUrl: "https://albertolvera.com"
|
externalUrl: "https://sabac.co"
|
||||||
weight: 81
|
weight: 961
|
||||||
showDate: false
|
showDate: false
|
||||||
showAuthor: false
|
showAuthor: false
|
||||||
showReadingTime: false
|
showReadingTime: false
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
title: "albertolvera.com"
|
title: "さばっこ"
|
||||||
tags: [个人网站]
|
tags: [个人网站, 博客]
|
||||||
externalUrl: "https://albertolvera.com"
|
externalUrl: "https://sabac.co"
|
||||||
weight: 81
|
weight: 961
|
||||||
showDate: false
|
showDate: false
|
||||||
showAuthor: false
|
showAuthor: false
|
||||||
showReadingTime: 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"
|
"College club site"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"title": "albertolvera.com",
|
|
||||||
"url": "https://albertolvera.com",
|
|
||||||
"source": "n/a",
|
|
||||||
"tags": [
|
|
||||||
"Personal site"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"title": "fahru.my.id",
|
"title": "fahru.my.id",
|
||||||
"url": "https://www.fahru.my.id",
|
"url": "https://www.fahru.my.id",
|
||||||
|
|
171
processUsers.js
|
@ -1,5 +1,5 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const crypto = require("crypto")
|
const crypto = require("crypto")
|
||||||
const puppeteer = require("puppeteer");
|
const puppeteer = require("puppeteer");
|
||||||
|
|
||||||
const configDir = "./exampleSite/config/_default";
|
const configDir = "./exampleSite/config/_default";
|
||||||
|
@ -12,107 +12,114 @@ var targetLangs = []
|
||||||
|
|
||||||
const configFiles = fs.readdirSync(configDir);
|
const configFiles = fs.readdirSync(configDir);
|
||||||
configFiles.forEach(file => {
|
configFiles.forEach(file => {
|
||||||
if (file.indexOf("languages.") > -1) {
|
if (file.indexOf("languages.") > -1) {
|
||||||
var lang = file.split(".")[1];
|
var lang = file.split(".")[1];
|
||||||
if (lang != defaultLang) {
|
if (lang != defaultLang) {
|
||||||
targetLangs.push(lang);
|
targetLangs.push(lang);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const indexFiles = fs.readdirSync(usersFolderPath);
|
const indexFiles = fs.readdirSync(usersFolderPath);
|
||||||
for (var i in targetLangs) {
|
for (var i in targetLangs) {
|
||||||
var targetFile = '_index.' + targetLangs[i] + '.md';
|
var targetFile = '_index.' + targetLangs[i] + '.md';
|
||||||
if (indexFiles.indexOf(targetFile) == -1) {
|
if (indexFiles.indexOf(targetFile) == -1) {
|
||||||
fs.copyFileSync(usersFolderPath + '_index.md', usersFolderPath + targetFile);
|
fs.copyFileSync(usersFolderPath + '_index.md', usersFolderPath + targetFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let rawdata = fs.readFileSync(usersFolderPath + 'users.json');
|
let rawdata = fs.readFileSync(usersFolderPath + 'users.json');
|
||||||
let users = JSON.parse(rawdata);
|
let users = JSON.parse(rawdata);
|
||||||
let userDict = {}
|
let userDict = {}
|
||||||
for (var i in users) {
|
for (var i in users) {
|
||||||
userDict[users[i].title.replaceAll("/", "-")] = true;
|
userDict[generateDirName(users[i].url)] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = fs.readdirSync(usersFolderPath);
|
const files = fs.readdirSync(usersFolderPath);
|
||||||
|
|
||||||
|
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
let stats = fs.statSync(usersFolderPath + files[file]);
|
let stats = fs.statSync(usersFolderPath + files[file]);
|
||||||
if (files[file] != 'users.json' && files[file].indexOf("_index.") == -1) {
|
if (files[file] != 'users.json' && files[file].indexOf("_index.") == -1) {
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
if (!userDict[files[file].replaceAll("/", "-")]) {
|
if (!userDict[files[file]]) {
|
||||||
console.log('deleting: ', files[file]);
|
console.log('deleting: ', files[file]);
|
||||||
fs.rmdirSync(usersFolderPath + files[file], { recursive: true, force: true });
|
fs.rmdirSync(usersFolderPath + files[file], { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('deleting: ', files[file]);
|
console.log('deleting: ', files[file]);
|
||||||
fs.unlinkSync(usersFolderPath + files[file]);
|
fs.unlinkSync(usersFolderPath + files[file]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cache = {};
|
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) {
|
async function convert(text, from, to) {
|
||||||
var options = {
|
var options = {
|
||||||
from: from,
|
from: from,
|
||||||
to: to
|
to: to
|
||||||
};
|
};
|
||||||
if (!cache[to])
|
if (!cache[to])
|
||||||
cache[to] = {};
|
cache[to] = {};
|
||||||
if (cache[to][text])
|
if (cache[to][text])
|
||||||
return cache[to][text];
|
return cache[to][text];
|
||||||
var translated_text = await translate(text, options);
|
var translated_text = await translate(text, options);
|
||||||
cache[to][text] = translated_text.text;
|
cache[to][text] = translated_text.text;
|
||||||
return translated_text.text;
|
return translated_text.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function translateFrontMatterTags(block, targetLang, tags) {
|
async function translateFrontMatterTags(block, targetLang, tags) {
|
||||||
var array = block.split("\n");
|
var array = block.split("\n");
|
||||||
var translatedBlock = "";
|
var translatedBlock = "";
|
||||||
for (var i = 0; i < array.length; i++) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
if (array[i].indexOf(":") > -1) {
|
if (array[i].indexOf(":") > -1) {
|
||||||
var elements = array[i].split(":");
|
var elements = array[i].split(":");
|
||||||
var newElement = "";
|
var newElement = "";
|
||||||
if (elements[0].indexOf("tags") != -1) {
|
if (elements[0].indexOf("tags") != -1) {
|
||||||
translatedTags = []
|
translatedTags = []
|
||||||
for (var j in tags) {
|
for (var j in tags) {
|
||||||
var tempTag = await convert(tags[j], defaultLang, targetLang);
|
var tempTag = await convert(tags[j], defaultLang, targetLang);
|
||||||
translatedTags.push(tempTag);
|
translatedTags.push(tempTag);
|
||||||
}
|
|
||||||
var trasnlatedTagsString = translatedTags.join(", ");
|
|
||||||
newElement = elements[0] + ": [" + trasnlatedTagsString + "]";
|
|
||||||
} else {
|
|
||||||
newElement = array[i];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newElement = array[i];
|
|
||||||
}
|
}
|
||||||
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
|
puppeteer
|
||||||
.launch({
|
.launch({
|
||||||
defaultViewport: {
|
defaultViewport: {
|
||||||
width: 1280,
|
width: 1280,
|
||||||
height: 800,
|
height: 800,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(async (browser) => {
|
.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\
|
title: \""+ users[i].title + "\"\n\
|
||||||
tags: ["+ users[i].tags + "]\n\
|
tags: ["+ users[i].tags + "]\n\
|
||||||
externalUrl: \""+ users[i].url + "\"\n\
|
externalUrl: \""+ users[i].url + "\"\n\
|
||||||
weight: "+ (i+1) +"\n\
|
weight: "+ (i + 1) + "\n\
|
||||||
showDate: false\n\
|
showDate: false\n\
|
||||||
showAuthor: false\n\
|
showAuthor: false\n\
|
||||||
showReadingTime: false\n\
|
showReadingTime: false\n\
|
||||||
|
@ -121,26 +128,22 @@ puppeteer
|
||||||
showViews: false\n\
|
showViews: false\n\
|
||||||
layoutBackgroundHeaderSpace: false\n\
|
layoutBackgroundHeaderSpace: false\n\
|
||||||
\r---\n";
|
\r---\n";
|
||||||
|
|
||||||
|
var dir = usersFolderPath + generateDirName(users[i].url);
|
||||||
|
|
||||||
//digest the title to create a folder
|
if (!fs.existsSync(dir)) {
|
||||||
var hash = crypto.createHash('md5');
|
fs.mkdirSync(dir);
|
||||||
hash.update(users[i].url);
|
console.log(i, users[i].title);
|
||||||
var dir = usersFolderPath + hash.digest('hex');
|
fs.writeFileSync(dir + '/index.md', userMDFile);
|
||||||
|
for (var j in targetLangs) {
|
||||||
|
var content = await translateFrontMatterTags(userMDFile, targetLangs[j], users[i].tags);
|
||||||
if (!fs.existsSync(dir)) {
|
fs.writeFileSync(dir + '/index.' + targetLangs[j] + '.md', content);
|
||||||
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 page.goto(users[i].url);
|
||||||
|
await page.screenshot({ path: dir + "/feature.jpg" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
||||||
});
|
});
|