Skip to content

Commit

Permalink
Merge pull request #375 from GetPublii/0.33.4
Browse files Browse the repository at this point in the history
0.33.4
  • Loading branch information
dziudek authored Mar 12, 2019
2 parents 4093ced + ce67d83 commit dd6981e
Show file tree
Hide file tree
Showing 34 changed files with 585 additions and 125 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.33.3 (build 11538)**
**Current version: 0.33.4 (build 11590)**

## Why Publii?
Unlike static-site generators that are often unwieldy and difficult to use, Publii provides an
Expand Down
5 changes: 5 additions & 0 deletions app/back-end/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class App {
this.sites = {};
this.sitesDir = null;
this.app.sitesDir = null;
this.db = false;

/*
* Run the app
Expand Down Expand Up @@ -193,6 +194,10 @@ class App {
};
}

if (this.db) {
this.db.close();
}

this.db = new sqlite(dbPath);
let tags = new Tags(this, {site});
let posts = new Posts(this, {site});
Expand Down
2 changes: 1 addition & 1 deletion app/back-end/builddata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"0.33.3","build":11544,"status":"Beta"}
{"version":"0.33.4","build":11590,"status":"Beta"}
41 changes: 24 additions & 17 deletions app/back-end/events/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,32 @@ class AppEvents {

if(appInstance.appConfig.sitesLocation) {
let appFilesHelper = new AppFiles(appInstance);
result = appFilesHelper.relocateSites(
appInstance.appConfig.sitesLocation,
config.sitesLocation,
event
);
}

if (appInstance.db) {
appInstance.db.close();
}

if(result) {
fs.writeFileSync(appInstance.appConfigPath, JSON.stringify(config));
appInstance.appConfig = config;
}
setTimeout(() => {
result = appFilesHelper.relocateSites(
appInstance.appConfig.sitesLocation,
config.sitesLocation,
event
);

appInstance.loadSites().then(() => {
event.sender.send('app-config-saved', {
status: true,
message: 'success-save',
sites: appInstance.sites
});
});
if(result) {
fs.writeFileSync(appInstance.appConfigPath, JSON.stringify(config));
appInstance.appConfig = config;
}

appInstance.loadSites().then(() => {
event.sender.send('app-config-saved', {
status: true,
message: 'success-save',
sites: appInstance.sites
});
});
}, 500);
}

return;
}
Expand Down
16 changes: 13 additions & 3 deletions app/back-end/events/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,26 @@ class DeployEvents {
self.deploymentProcess.send({
type: 'abort'
});
} catch(e) {

setTimeout(() => {
if (this.deploymentProcess) {
this.deploymentProcess.kill();
}
}, 2000);
} catch(e) {

}
}

event.sender.send('app-deploy-aborted', true);
});

ipcMain.on('app-deploy-test', function(event, data) {
self.testConnection(data.deploymentConfig, data.siteName);
ipcMain.on('app-deploy-test', async (event, data) => {
try {
await this.testConnection(data.deploymentConfig, data.siteName);
} catch (err) {
console.log('Test connection error:', err);
}
});
}

Expand Down
5 changes: 5 additions & 0 deletions app/back-end/events/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ class SiteEvents {
// Load newly created db
let siteDir = path.join(appInstance.sitesDir, config.name);
let dbPath = path.join(siteDir, 'input', 'db.sqlite');

if (appInstance.db) {
appInstance.db.close();
}

appInstance.db = new sqlite(dbPath);

if(result !== false) {
Expand Down
27 changes: 18 additions & 9 deletions app/back-end/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,20 @@ class Image extends Model {
}

console.log('JIMP COVER', finalWidth, ' x ', finalHeight);
image.cover(finalWidth, finalHeight)
.quality(imagesQuality)
.write(destinationPath, function() {
resolve(destinationPath);
});

if (finalWidth === Jimp.AUTO || finalHeight === Jimp.AUTO) {
image.resize(finalWidth, finalHeight)
.quality(imagesQuality)
.write(destinationPath, function() {
resolve(destinationPath);
});
} else {
image.cover(finalWidth, finalHeight)
.quality(imagesQuality)
.write(destinationPath, function() {
resolve(destinationPath);
});
}
}).catch(err => {
console.log(err);
reject(err);
Expand All @@ -286,7 +295,7 @@ class Image extends Model {
result = new Promise ((resolve, reject) => {
if (extension.toLowerCase() === '.png') {
sharp(originalPath)
.resize(finalWidth, finalHeight, { withoutEnlargement: true })
.resize(finalWidth, finalHeight, { withoutEnlargement: true, fastShrinkOnLoad: false })
.toBuffer()
.then(function (outputBuffer) {
let wstream = fs.createWriteStream(destinationPath);
Expand All @@ -297,7 +306,7 @@ class Image extends Model {
}).catch(err => reject(err))
} else {
sharp(originalPath)
.resize(finalWidth, finalHeight, { withoutEnlargement: true })
.resize(finalWidth, finalHeight, { withoutEnlargement: true, fastShrinkOnLoad: false })
.jpeg({
quality: imagesQuality
})
Expand Down Expand Up @@ -335,7 +344,7 @@ class Image extends Model {
result = new Promise ((resolve, reject) => {
if (extension.toLowerCase() === '.png') {
sharp(originalPath)
.resize(finalWidth, finalHeight, { fit: 'inside', withoutEnlargement: true })
.resize(finalWidth, finalHeight, { fit: 'inside', withoutEnlargement: true, fastShrinkOnLoad: false })
.toBuffer()
.then(function (outputBuffer) {
let wstream = fs.createWriteStream(destinationPath);
Expand All @@ -345,7 +354,7 @@ class Image extends Model {
}).catch(err => reject(err));
} else {
sharp(originalPath)
.resize(finalWidth, finalHeight, { fit: 'inside', withoutEnlargement: true })
.resize(finalWidth, finalHeight, { fit: 'inside', withoutEnlargement: true, fastShrinkOnLoad: false })
.jpeg({
quality: imagesQuality
})
Expand Down
3 changes: 3 additions & 0 deletions app/back-end/migrators/site-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SiteConfigMigrator {
delete siteConfig.author;
fs.writeFileSync(configFilePath, JSON.stringify(siteConfig), {'flags': 'w'});

// close DB connection
db.close();

// Return modified (or not) site config
return siteConfig;
}
Expand Down
5 changes: 5 additions & 0 deletions app/back-end/modules/import/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Import {
}

const dbPath = path.join(this.appInstance.sitesDir, this.siteName, 'input', 'db.sqlite');

if (this.appInstance.db) {
this.appInstance.db.close();
}

this.appInstance.db = new sqlite(dbPath);
}

Expand Down
1 change: 1 addition & 0 deletions app/back-end/modules/import/wxr-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class WxrParser {
results = xmlParser.toJson(this.fileContent);
results = JSON.parse(results);
} catch(e) {
console.log('An error occurred:', e);
return false;
}

Expand Down
12 changes: 1 addition & 11 deletions app/back-end/modules/render-html/contexts/post-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,7 @@ class RendererContextPostPreview extends RendererContext {
};
});

this.tags.sort((tagA, tagB) => {
if(tagA.name < tagB.name) {
return -1;
}

if(tagA.name > tagB.name) {
return 1;
}

return 0;
});
this.tags.sort((tagA, tagB) => tagA.name.localeCompare(tagB.name));
}

this.metaTitle = 'It is an example value for the preview mode';
Expand Down
1 change: 0 additions & 1 deletion app/back-end/modules/render-html/contexts/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const sqlString = require('sqlstring');
* Class used create context
* for the single post theme views
*/

class RendererContextPost extends RendererContext {
loadData() {
// Retrieve meta data
Expand Down
20 changes: 5 additions & 15 deletions app/back-end/modules/render-html/items/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class PostItem {
}
}

if(this.siteConfig.advanced.urls.cleanUrls) {
if (this.siteConfig.advanced.urls.cleanUrls) {
postURL = this.siteConfig.domain + '/' + this.post.slug + '/';

if(this.renderer.previewMode || this.renderer.siteConfig.advanced.urls.addIndex) {
if (this.renderer.previewMode || this.renderer.siteConfig.advanced.urls.addIndex) {
postURL += 'index.html';
}
}
Expand All @@ -65,23 +65,13 @@ class PostItem {

this.postData.featuredImage = {};

if(this.renderer.cachedItems.featuredImages[this.postData.id]) {
if (this.renderer.cachedItems.featuredImages[this.postData.id]) {
this.postData.featuredImage = this.renderer.cachedItems.featuredImages[this.postData.id];
}

if(this.renderer.cachedItems.postTags[this.postID]) {
if (this.renderer.cachedItems.postTags[this.postID]) {
this.postData.tags = this.renderer.cachedItems.postTags[this.postID].map(tagID => this.renderer.cachedItems.tags[tagID]);
this.postData.tags.sort((tagA, tagB) => {
if(tagA.name.toLowerCase() < tagB.name.toLowerCase()) {
return -1;
}

if(tagA.name.toLowerCase() > tagB.name.toLowerCase()) {
return 1;
}

return 0;
});
this.postData.tags.sort((tagA, tagB) => tagA.name.localeCompare(tagB.name));
} else {
this.postData.tags = [];
}
Expand Down
9 changes: 8 additions & 1 deletion app/back-end/modules/render-html/renderer-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class RendererContext {
tags = tags.filter(tag => tag.postsNumber > 0);
}

tags.sort((tagA, tagB) => tagA.name.localeCompare(tagB.name));

return tags;
}

Expand All @@ -170,6 +172,8 @@ class RendererContext {
authors = authors.filter(author => author.postsNumber > 0);
}

authors.sort((authorA, authorB) => authorA.name.localeCompare(authorB.name));

return authors;
}

Expand Down Expand Up @@ -236,7 +240,10 @@ class RendererContext {
bodyCustomCode: this.siteConfig.advanced.customBodyCode || '',
footerCustomCode: this.siteConfig.advanced.customFooterCode || '',
footerAmpCustomCode: this.siteConfig.advanced.customFooterAmpCode || '',
customHTML: this.siteConfig.advanced.customHTML || false
customHTML: this.siteConfig.advanced.customHTML || false,
utils: {
currentYear: new Date().getFullYear()
}
};

// In AMP mode create special global @amp variable
Expand Down
1 change: 1 addition & 0 deletions app/back-end/modules/render-html/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class Renderer {
this.generateAMP();
console.timeEnd("RENDERING");
this.sendProgress(100, 'Website files are ready to upload');
this.db.close();
}

/**
Expand Down
13 changes: 12 additions & 1 deletion app/back-end/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Site {
let dbPath = path.join(this.siteDir, 'input', 'db.sqlite');
let db = new sqlite(dbPath);
db.exec(fs.readFileSync(this.application.basedir + '/back-end/sql/1.0.0.sql', 'utf8'));
db.close();
}

/*
Expand All @@ -107,6 +108,7 @@ class Site {
name: authorName,
slug: slug(authorName).toLowerCase()
});
db.close();
}

/*
Expand Down Expand Up @@ -251,6 +253,8 @@ class Site {
sender.send('app-site-regenerate-thumbnails-success', true);
}
});

db.close();
}

/**
Expand Down Expand Up @@ -309,7 +313,14 @@ class Site {
*/
static delete(appInstance, name) {
let sitePath = path.join(appInstance.sitesDir, name);
fs.removeSync(sitePath);

if (appInstance.db) {
appInstance.db.close();
}

setTimeout(() => {
fs.removeSync(sitePath);
}, 500);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"productName": "Publii",
"name": "Publii",
"version": "0.33.3",
"version": "0.33.4",
"description": "Static Site CMS",
"main": "main.js",
"scripts": {
Expand Down
Loading

0 comments on commit dd6981e

Please sign in to comment.