Skip to content

Commit

Permalink
Merge branch 'v.0.46.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dziudek committed Dec 22, 2024
2 parents 443986c + f8d938a commit bbb433b
Show file tree
Hide file tree
Showing 63 changed files with 599 additions and 1,207 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[Publii](https://getpublii.com/) is a desktop-based CMS for Windows, Mac and Linux that makes creating static websites fast
and hassle-free, even for beginners.

**Current version: 0.46.2 (build 16966)**
**Current version: 0.46.3 (build 17008)**

## Why Publii?
Unlike static-site generators that are often unwieldy and difficult to use, Publii provides an
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class App {

// Detect missing themes
if (!fs.existsSync(path.join(userThemesPath, file))) {
fs.mkdirSync(path.join(userThemesPath, file));
fs.mkdirSync(path.join(userThemesPath, file), { recursive: true });

try {
fs.copySync(
Expand Down
4 changes: 2 additions & 2 deletions app/back-end/builddata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.46.2",
"build": 16966
"version": "0.46.3",
"build": 17008
}
6 changes: 3 additions & 3 deletions app/back-end/events/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class AppEvents {
if (extension === '.zip') {
let zipPath = path.join(themesLoader.themesPath, '__TEMP__');
let zip = new AdmZip(config.sourcePath);
fs.mkdirSync(zipPath);
fs.mkdirSync(zipPath, { recursive: true });
zip.extractAllTo(zipPath, true);

let dirs = fs.readdirSync(zipPath).filter(function(file) {
Expand Down Expand Up @@ -261,7 +261,7 @@ class AppEvents {
if (extension === '.zip') {
let zipPath = path.join(languagesLoader.languagesPath, '__TEMP__');
let zip = new AdmZip(config.sourcePath);
fs.mkdirSync(zipPath);
fs.mkdirSync(zipPath, { recursive: true });
zip.extractAllTo(zipPath, true);

let dirs = fs.readdirSync(zipPath).filter(function(file) {
Expand Down Expand Up @@ -341,7 +341,7 @@ class AppEvents {
if (extension === '.zip' || extension === '') {
if (extension === '.zip') {
let zipPath = path.join(pluginsLoader.pluginsPath, '__TEMP__');
fs.mkdirSync(zipPath);
fs.mkdirSync(zipPath, { recursive: true });
let zip = new AdmZip(config.sourcePath);
zip.extractAllTo(zipPath, true);

Expand Down
2 changes: 1 addition & 1 deletion app/back-end/events/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class DeployEvents {
appDir: this.app.appDir,
sitesDir: this.app.sitesDir,
siteConfig: deploymentConfig,
useFtpAlt: this.app.appConfig.experimentalFeatureAppAutoBeautifySourceCode
useFtpAlt: this.app.appConfig.experimentalFeatureAppFtpAlt
});

this.deploymentProcess.on('message', function(data) {
Expand Down
4 changes: 2 additions & 2 deletions app/back-end/events/plugins-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PluginsApiEvents {
let filePath = path.join(appInstance.sitesDir, siteName, 'input', 'config', 'plugins', pluginName, fileName);

if (!fs.existsSync(path.join(appInstance.sitesDir, siteName, 'input', 'config', 'plugins', pluginName))) {
fs.mkdirSync(path.join(appInstance.sitesDir, siteName, 'input', 'config', 'plugins', pluginName));
fs.mkdirSync(path.join(appInstance.sitesDir, siteName, 'input', 'config', 'plugins', pluginName), { recursive: true });
}

try {
Expand All @@ -82,7 +82,7 @@ class PluginsApiEvents {
let filePath = path.join(appInstance.sitesDir, siteName, 'input', 'languages', fileName);

if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
fs.mkdirSync(dirPath, { recursive: true });
}

try {
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/helpers/app-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AppFilesHelper {
}

try {
fs.mkdirSync(path.join(newLocation, site));
fs.mkdirSync(path.join(newLocation, site), { recursive: true });

fs.copySync(
path.join(oldLocation, site),
Expand Down
8 changes: 4 additions & 4 deletions app/back-end/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ class Image extends Model {

// If dir not exists - create it
if (!Utils.dirExists(dirPath)) {
fs.mkdirSync(dirPath);
fs.mkdirSync(dirPath, { recursive: true });

if (responsiveDirPath !== '') {
fs.mkdirSync(responsiveDirPath);
fs.mkdirSync(responsiveDirPath, { recursive: true });
}
}

// If gallery directory not exist - create it
if (galleryDirPath !== '' && !Utils.dirExists(galleryDirPath)) {
fs.mkdirSync(galleryDirPath);
fs.mkdirSync(galleryDirPath, { recursive: true });
}

// If responsive directory not exist - create it
if (responsiveDirPath !== '' && !Utils.dirExists(responsiveDirPath)) {
fs.mkdirSync(responsiveDirPath);
fs.mkdirSync(responsiveDirPath, { recursive: true });
}

newPath = this.generateFileName(fileName, 1, dirPath, galleryDirPath);
Expand Down
6 changes: 3 additions & 3 deletions app/back-end/modules/backup/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Backup {

if(!Utils.dirExists(backupsPath)) {
if(Utils.dirExists(backupsDir)) {
fs.mkdirSync(backupsPath);
fs.mkdirSync(backupsPath, { recursive: true });
} else {
return false;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ class Backup {

if(!Utils.dirExists(backupsPath)) {
if(Utils.dirExists(backupsDir)) {
fs.mkdirSync(backupsPath);
fs.mkdirSync(backupsPath, { recursive: true });
} else {
return {
type: 'app-backup-create-error',
Expand Down Expand Up @@ -238,7 +238,7 @@ class Backup {
}

if(!Utils.dirExists(tempDir)) {
fs.mkdirSync(tempDir);
fs.mkdirSync(tempDir, { recursive: true });

if(!Utils.dirExists(tempDir)) {
return {
Expand Down
8 changes: 4 additions & 4 deletions app/back-end/modules/deploy/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Deployment {
case 'github-pages': connection = new GithubPages(deploymentConfig); break;
case 'gitlab-pages': connection = new GitlabPages(); break;
default:
if (this.useAltFtp) {
if (this.useAltFtp) {
connection = new FTPAlt();
} else {
connection = new FTP();
Expand Down Expand Up @@ -101,7 +101,7 @@ class Deployment {
case 'google-cloud': this.client = new GoogleCloud(this); break;
case 'manual': this.client = new ManualDeployment(this); break;
default:
if (this.useAltFtp) {
if (this.useAltFtp) {
this.client = new FTPAlt(this);
} else {
this.client = new FTP(this);
Expand Down Expand Up @@ -145,7 +145,7 @@ class Deployment {
continue;
}

if (filePath === '.htaccess' || filePath === '_redirects') {
if (filePath === '.htaccess' || filePath === '.htpasswd' || filePath === '_redirects') {
let excludedProtocols = ['s3', 'github-pages', 'google-cloud', 'netlify'];

if (excludedProtocols.indexOf(this.siteConfig.deployment.protocol) === -1) {
Expand Down Expand Up @@ -554,7 +554,7 @@ class Deployment {
filelist.push(normalizePath(path.join(dir.replace(self.inputDir, ''), file)));
filelist = self.readDirRecursiveSync(path.join(dir, file), filelist);
} else {
if(file.indexOf('.') !== 0 || file === '.htaccess' || file === '_redirects') {
if(file.indexOf('.') !== 0 || file === '.htaccess' || file === '.htpasswd' || file === '_redirects') {
filelist.push(normalizePath(path.join(dir.replace(self.inputDir, ''), file)));
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/modules/deploy/libraries/netlify-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class NetlifyAPI {
}

fileIsNotExcluded (file) {
return file.indexOf('.') !== 0 || file === '.htaccess' || file === '_redirects';
return file.indexOf('.') !== 0 || file === '.htaccess' || file === '.htpasswd' || file === '_redirects';
}

getFilePath (dir, file, includeInputDir = false) {
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/modules/import/wxr-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ class WxrParser {
let dirPath = path.join(destinationPath, (nextImg.postID).toString());

if(!Utils.dirExists(dirPath)) {
fs.mkdirSync(dirPath);
fs.mkdirSync(dirPath, { recursive: true });
}

let image = nextImg.imgUrl;
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/modules/render-html/helpers/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ class ContentHelper {
let regexp = new RegExp('#INTERNAL_LINK#\/' + type + '\/[0-9]{1,}', 'gmi');

if (type === 'file' || type === 'author') {
regexp = new RegExp('#INTERNAL_LINK#\/' + type + '\/.*?\"', 'gmi');
regexp = new RegExp('#INTERNAL_LINK#\/' + type + '\/.*?[\"\']{1,1}', 'gmi');
}

let urls = [...new Set(text.match(regexp))];
Expand Down
1 change: 1 addition & 0 deletions app/back-end/modules/render-html/helpers/sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class Sitemap {
'assets',
'media',
'.htaccess',
'.htpasswd',
'_redirects',
'robots.txt',
'feed.xml',
Expand Down
49 changes: 29 additions & 20 deletions app/back-end/modules/render-html/helpers/specs/url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,80 +51,89 @@ describe('URL helper', function() {
});

describe('#URLHelper.createPaginationPermalink', function() {
let urlsConfig = {
urls: {
cleanUrls: false,
tagsPrefix: '',
authorsPrefix: 'authors',
pageName: 'page',
errorPage: '404.html',
searchPage: 'search.html'
let themeConfig = {
supportedFeatures: {
postsPage: false
}
};

let siteConfig = {
domain: 'http://example.com',
advanced: {
urls: {
cleanUrls: false,
tagsPrefix: '',
authorsPrefix: 'authors',
pageName: 'page',
errorPage: '404.html',
searchPage: 'search.html'
}
}
};

it('should create a proper URL for different types of pages', function () {
assert.equal(
'http://example.com/lorem-ipsum/page/2/',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 2, '', 'lorem-ipsum')
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 2, '', 'lorem-ipsum')
);

assert.equal(
'http://example.com/page/2/',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 2, '', false)
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 2, '', false)
);

assert.equal(
'http://example.com/authors/lorem-ipsum/page/2/',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 2, 'author', 'lorem-ipsum')
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 2, 'author', 'lorem-ipsum')
);
});

it('should create a proper URL for the first page', function () {
assert.equal(
'http://example.com/lorem-ipsum/',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 1, '', 'lorem-ipsum')
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 1, '', 'lorem-ipsum')
);

assert.equal(
'http://example.com/',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 1, '', false)
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 1, '', false)
);

assert.equal(
'http://example.com/authors/lorem-ipsum/',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 1, 'author', 'lorem-ipsum')
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 1, 'author', 'lorem-ipsum')
);
});

it('should create a proper URL with index.html when it is required', function () {
assert.equal(
'http://example.com/lorem-ipsum/index.html',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 1, '', 'lorem-ipsum', true)
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 1, '', 'lorem-ipsum', true)
);

assert.equal(
'http://example.com/index.html',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 1, '', false, true)
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 1, '', false, true)
);

assert.equal(
'http://example.com/authors/lorem-ipsum/index.html',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 1, 'author', 'lorem-ipsum', true)
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 1, 'author', 'lorem-ipsum', true)
);

assert.equal(
'http://example.com/lorem-ipsum/page/2/index.html',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 2, '', 'lorem-ipsum', true)
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 2, '', 'lorem-ipsum', true)
);

assert.equal(
'http://example.com/page/2/index.html',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 2, '', false, true)
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 2, '', false, true)
);

assert.equal(
'http://example.com/authors/lorem-ipsum/page/2/index.html',
URLHelper.createPaginationPermalink('http://example.com', urlsConfig, 2, 'author', 'lorem-ipsum', true)
URLHelper.createPaginationPermalink(siteConfig, themeConfig, 2, 'author', 'lorem-ipsum', true)
);
});
});
Expand Down
32 changes: 27 additions & 5 deletions app/back-end/modules/render-html/helpers/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,20 @@ class TemplateHelper {
let overridedFilesAndDirs = false;

if(Utils.dirExists(partialsPath)) {
filesAndDirs = fs.readdirSync(partialsPath);
filesAndDirs = this.getHbsFilesRecursively(partialsPath);
filesAndDirs = filesAndDirs.map(file => file.replace(partialsPath + '/', ''));
}

if(Utils.dirExists(overridedPartialsPath)) {
overridedFilesAndDirs = fs.readdirSync(overridedPartialsPath);
overridedFilesAndDirs = this.getHbsFilesRecursively(overridedPartialsPath);
overridedFilesAndDirs = overridedFilesAndDirs.map(file => file.replace(overridedPartialsPath + '/', ''));
}

if(!filesAndDirs && !overridedFilesAndDirs) {
if (!filesAndDirs.length && !overridedFilesAndDirs.length) {
return userPartials;
}

for(let i = 0; i < filesAndDirs.length; i++) {
for (let i = 0; i < filesAndDirs.length; i++) {
if (filesAndDirs[i].substr(-4) !== '.hbs') {
continue;
}
Expand All @@ -368,7 +370,7 @@ class TemplateHelper {
}
}

for(let i = 0; i < overridedFilesAndDirs.length; i++) {
for (let i = 0; i < overridedFilesAndDirs.length; i++) {
if (overridedFilesAndDirs[i].substr(-4) !== '.hbs') {
continue;
}
Expand All @@ -385,6 +387,26 @@ class TemplateHelper {

return userPartials;
}

getHbsFilesRecursively (dir) {
let results = [];
let list = fs.readdirSync(dir);

list.forEach(file => {
let filePath = path.join(dir, file);
let stat = fs.statSync(filePath);

if (stat.isDirectory()) {
results = results.concat(this.getHbsFilesRecursively(filePath));
} else {
if (path.extname(file) === '.hbs') {
results.push(filePath);
}
}
});

return results;
}
}

module.exports = TemplateHelper;
Loading

0 comments on commit bbb433b

Please sign in to comment.