Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async renderCustomPage() {
const files = fse.readdirSync(urlJoin(this.themePath, 'templates'), { withFileTypes: true })
const customTemplates = files
.filter(item => !item.isDirectory())
.map(item => item.name)
.filter(junk.not)
.filter((name: string) => {
return ![
'index.ejs',
'post.ejs',
'tag.ejs',
'tags.ejs',
'archives.ejs',
// 👇 Gridea protected word, because these filename is gridea folder's name
'images.ejs',
'media.ejs',
'post-images.ejs',
'styles.ejs',
'tag.ejs',
'tags.ejs',
].includes(name)
})
fs.readdirSync(filesPath).forEach( function(fileName)
{
if (junk.not(fileName))
{
files.push( filesPath +"/"+ fileName );
}
});
await Promise.all(files.map(async (filename: string) => {
const targetPath = path.join(directoryPath, filename);
let stats;
try {
stats = await lstatAsync(targetPath);
} catch (err) {
console.warn('lstatAsync got error:', err);
}
const isDirectory = stats &&
stats.isDirectory() &&
junk.not(filename) &&
filename.indexOf('.') !== 0;
if (isDirectory) {
try {
await accessAsync(targetPath, fs.constants.R_OK);
targetFiles.push(filename);
} catch (error) {
console.warn('accessAsync got error:', error);
}
}
}));
async getThemeList() {
let themes = await fse.readdir(this.themeDir)
themes = themes.filter(junk.not)
const result = await Promise.all(themes.map(async (item: string) => {
const data = {
folder: item,
name: item,
version: '',
author: '',
repository: '',
}
const themeConfigPath = path.join(this.themeDir, item, 'config.json')
if (fse.existsSync(themeConfigPath)) {
const config = fse.readJSONSync(themeConfigPath)
data.name = config.name
data.version = config.version
data.author = config.repository
data.repository = config.repository
}
files = files.filter(file => junk.not(path.basename(file)));
}
.filter(filePath => junk.not(path.basename(filePath)))
.map(async filePath => {
recursiveReaddirSync = (dirPath, rootDir) => {
let stats;
let list = [];
const files = fs.readdirSync(dirPath).filter(junk.not);
files.forEach((file) => {
const fullPath = path.join(dirPath, file);
stats = fs.lstatSync(fullPath);
if (stats.isDirectory()) {
list = list.concat(this.recursiveReaddirSync(fullPath, rootDir));
} else {
list.push({
path: path.relative(rootDir, fullPath),
size: filesize(stats.size),
fullPath,
statsSize: stats.size,
});
}
});
list = list.sort((a, b) => {
recursiveReaddirSync = (dirPath, rootDir) => {
let stats;
let list = [];
const files = fs.readdirSync(dirPath).filter(junk.not);
files.forEach((file) => {
const fullPath = path.join(dirPath, file);
stats = fs.lstatSync(fullPath);
if (stats.isDirectory()) {
list = list.concat(this.recursiveReaddirSync(fullPath, rootDir));
} else {
list.push({
path: path.relative(rootDir, fullPath),
fullPath,
});
}
});
list = list.sort((a, b) => {
return a.path.localeCompare(b.path);
});
.filter(item => {
const base = path.basename(item);
return junk.not(base) && base.indexOf('_') !== 0;
})
.filter(file => !isDir.sync(path.join(this.path, file)));
export const readdirSync = (targetPath) => {
if (pathExists.sync(targetPath)) {
return fs.readdirSync(targetPath).filter(junk.not);
}
return [];
};