Skip to content

Commit

Permalink
Merge branch 'v.0.46'
Browse files Browse the repository at this point in the history
  • Loading branch information
dziudek committed Aug 14, 2024
2 parents 0f8c211 + cc10fac commit 2379e3c
Show file tree
Hide file tree
Showing 212 changed files with 57,735 additions and 44,034 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.0
v20.15.1
4 changes: 2 additions & 2 deletions 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.45.2 (build 16609)**
**Current version: 0.46.0 (build 16889)**

## Why Publii?
Unlike static-site generators that are often unwieldy and difficult to use, Publii provides an
Expand Down Expand Up @@ -82,4 +82,4 @@ Support this project by becoming a sponsor. Your logo will show up here with a l


## License
Copyright (c) 2022 TidyCustoms. General Public License v3.0, read [LICENSE](https://getpublii.com/license.html) for details.
Copyright (c) 2024 TidyCustoms. General Public License v3.0, read [LICENSE](https://getpublii.com/license.html) for details.
18 changes: 17 additions & 1 deletion app/back-end/app-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ contextBridge.exposeInMainWorld('mainProcessAPI', {
'app-post-load',
'app-post-save',
'app-post-cancel',
'app-page-load',
'app-page-save',
'app-page-cancel',
'app-pages-hierarchy-load',
'app-pages-hierarchy-save',
'app-image-upload',
'app-image-upload-remove',
'app-post-delete',
'app-post-duplicate',
'app-post-status-change',
'app-page-delete',
'app-page-duplicate',
'app-page-status-change',
'app-site-regenerate-thumbnails',
'app-site-abort-regenerate-thumbnails',
'app-preview-render',
Expand All @@ -67,6 +75,7 @@ contextBridge.exposeInMainWorld('mainProcessAPI', {
'app-license-accept',
'app-deploy-render-abort',
'app-deploy-abort',
'app-deploy-continue',
'app-deploy-render',
'app-deploy-upload',
'app-sync-is-done',
Expand Down Expand Up @@ -115,7 +124,8 @@ contextBridge.exposeInMainWorld('mainProcessAPI', {
'app-wxr-import-progress',
'app-show-search-form',
'block-editor-undo',
'block-editor-redo'
'block-editor-redo',
'no-remote-files'
];

if (validChannels.includes(channel)) {
Expand Down Expand Up @@ -158,6 +168,12 @@ contextBridge.exposeInMainWorld('mainProcessAPI', {
'app-post-deleted',
'app-post-duplicated',
'app-post-status-changed',
'app-page-loaded',
'app-page-saved',
'app-page-deleted',
'app-page-duplicated',
'app-page-status-changed',
'app-pages-hierarchy-loaded',
'app-site-regenerate-thumbnails-error',
'app-site-regenerate-thumbnails-success',
'app-preview-rendered',
Expand Down
7 changes: 7 additions & 0 deletions app/back-end/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const url = require('url');
const { screen, shell, nativeTheme, Menu, dialog, BrowserWindow } = require('electron');
// Collection classes
const Posts = require('./posts.js');
const Pages = require('./pages.js');
const Tags = require('./tags.js');
const Authors = require('./authors.js');
const Themes = require('./themes.js');
Expand Down Expand Up @@ -224,9 +225,11 @@ class App {
this.db = new DBUtils(new Database(dbPath));
let tags = new Tags(this, {site});
let posts = new Posts(this, {site});
let pages = new Pages(this, {site});
let authors = new Authors(this, {site});
let themes = new Themes(this, {site});
let themeDir = path.join(siteDir, 'input', 'themes', themes.currentTheme(true));
let themeOverridesDir = path.join(siteDir, 'input', 'themes', themes.currentTheme(true) + '-override');
let themeConfig = Themes.loadThemeConfig(themeConfigPath, themeDir);
let menuStructure = fs.readFileSync(menuConfigPath, 'utf8');
let parsedMenuStructure = {};
Expand All @@ -240,14 +243,18 @@ class App {
return {
status: true,
posts: posts.load(),
pages: pages.load(),
tags: tags.load(),
authors: authors.load(),
postsTags: posts.loadTagsXRef(),
postsAuthors: posts.loadAuthorsXRef(),
pagesAuthors: pages.loadAuthorsXRef(),
postTemplates: themes.loadPostTemplates(),
pageTemplates: themes.loadPageTemplates(),
tagTemplates: themes.loadTagTemplates(),
authorTemplates: themes.loadAuthorTemplates(),
themes: themes.load(),
themeHasOverrides: Utils.dirExists(themeOverridesDir),
themeSettings: themeConfig,
menuStructure: parsedMenuStructure,
siteDir: siteDir
Expand Down
27 changes: 23 additions & 4 deletions app/back-end/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs-extra');
const path = require('path');
const Model = require('./model.js');
const Authors = require('./authors.js');
const Pages = require('./pages.js');
const Posts = require('./posts.js');
const slug = require('./helpers/slug');
const ImageHelper = require('./helpers/image.helper.js');
Expand All @@ -23,6 +24,7 @@ class Author extends Model {
this.id = parseInt(authorData.id, 10);
this.authorsData = new Authors(appInstance, authorData);
this.postsData = new Posts(appInstance, authorData);
this.pagesData = new Pages(appInstance, authorData);
this.storeMode = storeMode;

if (authorData.additionalData) {
Expand Down Expand Up @@ -133,6 +135,7 @@ class Author extends Model {
message: 'author-added',
authorID: this.id,
postsAuthors: this.postsData.loadAuthorsXRef(),
pagesAuthors: this.pagesData.loadAuthorsXRef(),
authors: this.authorsData.load()
};
}
Expand Down Expand Up @@ -292,7 +295,7 @@ class Author extends Model {
featuredImage = path.parse(this.additionalData.featuredImage).base;
}

// If post is cancelled - get the previous featured image
// If author is cancelled - get the previous featured image
if (cancelEvent && this.id !== 0) {
let featuredImageSqlQuery = `SELECT additional_data FROM authors WHERE id = @id`;

Expand All @@ -313,6 +316,12 @@ class Author extends Model {
authorDir = 'temp';
}

let imagesInAuthorViewSettings = [];

if (this.additionalData && this.additionalData.viewConfig) {
imagesInAuthorViewSettings = Object.values(this.additionalData.viewConfig).filter(item => item.type === "image").map(item => item.value);
}

// Iterate through images
for (let i in images) {
let imagePath = images[i];
Expand All @@ -323,7 +332,14 @@ class Author extends Model {
continue;
}

if ((cancelEvent && authorDir === 'temp') || featuredImage !== imagePath) {
// Remove files which does not exist as featured image and authorViewSettings
if(
(cancelEvent && authorDir === 'temp') ||
(
imagesInAuthorViewSettings.indexOf(imagePath) === -1 &&
featuredImage !== imagePath
)
) {
try {
fs.unlinkSync(fullPath);
} catch(e) {
Expand All @@ -337,8 +353,11 @@ class Author extends Model {
// Clean unused avatar images
let themesHelper = new Themes(this.application, { site: this.site });
let themeConfigPath = path.join(this.application.sitesDir, this.site, 'input', 'config', 'theme.config.json');
let themeConfigString = fs.readFileSync(themeConfigPath, 'utf8');
themesHelper.checkAndCleanImages(themeConfigString);

if (fs.fileExists(themeConfigPath)) {
let themeConfigString = fs.readFileSync(themeConfigPath, 'utf8');
themesHelper.checkAndCleanImages(themeConfigString);
}
}

/*
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.45.2",
"build": 16609
"version": "0.46.0",
"build": 16889
}
1 change: 1 addition & 0 deletions app/back-end/events/_modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
AppEvents: require('./app.js'),
CreditsEvents: require('./credits'),
ImageUploaderEvents: require('./image-uploader.js'),
PageEvents: require('./page.js'),
PostEvents: require('./post.js'),
SiteEvents: require('./site.js'),
TagEvents: require('./tag.js'),
Expand Down
17 changes: 16 additions & 1 deletion app/back-end/events/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ class DeployEvents {
event.sender.send('app-deploy-aborted', true);
});

ipcMain.on('app-deploy-continue', function() {
if (self.deploymentProcess) {
try {
self.deploymentProcess.send({
type: 'continue-sync'
});

self.deploymentProcess = false;
} catch(e) {
console.log(e);
self.deploymentProcess = false;
}
}
});

ipcMain.on('app-deploy-test', async (event, data) => {
try {
await this.testConnection(data.deploymentConfig, data.siteName, data.uuid);
Expand Down Expand Up @@ -162,7 +177,7 @@ class DeployEvents {
});

this.deploymentProcess.on('message', function(data) {
if(data.type === 'web-contents') {
if (data.type === 'web-contents') {
if(data.value) {
self.app.mainWindow.webContents.send(data.message, data.value);
} else {
Expand Down
102 changes: 102 additions & 0 deletions app/back-end/events/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const fs = require('fs');
const path = require('path');
const ipcMain = require('electron').ipcMain;
const Page = require('../page.js');

/*
* Events for the IPC communication regarding pages
*/

class PageEvents {
constructor(appInstance) {
this.app = appInstance;

// Load
ipcMain.on('app-page-load', function (event, pageData) {
let page = new Page(appInstance, pageData);
let result = page.load();
event.sender.send('app-page-loaded', result);
});

// Save
ipcMain.on('app-page-save', function (event, pageData) {
let page = new Page(appInstance, pageData);
let result = page.save();
event.sender.send('app-page-saved', result);
});

// Delete
ipcMain.on('app-page-delete', function (event, pageData) {
let result = false;

for(let i = 0; i < pageData.ids.length; i++) {
let page = new Page(appInstance, {
site: pageData.site,
id: pageData.ids[i]
});

result = page.delete();
}

event.sender.send('app-page-deleted', result);
});

// Delete
ipcMain.on('app-page-duplicate', function (event, pageData) {
let result = false;

for(let i = 0; i < pageData.ids.length; i++) {
let page = new Page(appInstance, {
site: pageData.site,
id: pageData.ids[i]
});

result = page.duplicate();
}

event.sender.send('app-page-duplicated', result);
});

// Status change
ipcMain.on('app-page-status-change', function (event, pageData) {
let result = false;

for(let i = 0; i < pageData.ids.length; i++) {
let page = new Page(appInstance, {
site: pageData.site,
id: pageData.ids[i]
});

result = page.changeStatus(pageData.status, pageData.inverse);
}

event.sender.send('app-page-status-changed', result);
});

// Cancelled edition
ipcMain.on('app-page-cancel', function(event, pageData) {
let page = new Page(appInstance, pageData);
let result = page.checkAndCleanImages(true);
event.sender.send('app-page-cancelled', result);
});

// Load pages hierarchy
ipcMain.on('app-pages-hierarchy-load', (event, siteName) => {
let pagesFile = path.join(this.app.sitesDir, siteName, 'input', 'config', 'pages.config.json');

if (fs.existsSync(pagesFile)) {
event.sender.send('app-pages-hierarchy-loaded', JSON.parse(fs.readFileSync(pagesFile, { encoding: 'utf8' })));
} else {
event.sender.send('app-pages-hierarchy-loaded', null);
}
});

// Save pages hierarchy
ipcMain.on('app-pages-hierarchy-save', (event, pagesData) => {
let pagesFile = path.join(this.app.sitesDir, pagesData.siteName, 'input', 'config', 'pages.config.json');
fs.writeFileSync(pagesFile, JSON.stringify(pagesData.hierarchy, null, 4), { encoding: 'utf8' });
});
}
}

module.exports = PageEvents;
6 changes: 5 additions & 1 deletion app/back-end/events/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class PreviewEvents {
errorDesc = data.result[0].message + "\n\n" + data.result[0].desc;
}

if (typeof errorDesc === 'object') {
errorDesc = errorDesc.translation;
}

event.sender.send('app-preview-render-error', {
message: [{
message: errorTitle,
Expand Down Expand Up @@ -170,7 +174,7 @@ class PreviewEvents {

url = path.join(basePath, 'index.html');

if (mode === 'tag' || mode === 'post' || mode === 'author') {
if (mode === 'tag' || mode === 'post' || mode === 'page' || mode === 'author') {
url = path.join(basePath, 'preview.html');
}

Expand Down
2 changes: 2 additions & 0 deletions app/back-end/events/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SiteEvents {

// Prepare settings
config.settings.name = slug(config.settings.name);
config.settings.advanced.urls.postsPrefix = slug(config.settings.advanced.urls.postsPrefix);
config.settings.advanced.urls.tagsPrefix = slug(config.settings.advanced.urls.tagsPrefix);
config.settings.advanced.urls.authorsPrefix = slug(config.settings.advanced.urls.authorsPrefix);
config.settings.advanced.urls.pageName = slug(config.settings.advanced.urls.pageName);
Expand Down Expand Up @@ -392,6 +393,7 @@ class SiteEvents {
newConfig: {
config: themeConfig.config,
customConfig: themeConfig.customConfig,
pageConfig: themeConfig.pageConfig,
postConfig: themeConfig.postConfig,
tagConfig: themeConfig.tagConfig,
authorConfig: themeConfig.authorConfig,
Expand Down
15 changes: 13 additions & 2 deletions app/back-end/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Image extends Model {

if (imageData.id === 'website') {
this.id = 'website';
} else if (imageData.id === 'defaults') {
this.id = 'defaults';
}

// App instance
Expand Down Expand Up @@ -95,9 +97,18 @@ class Image extends Model {
let galleryDirPath = '';
let responsiveDirPath = '';

if (this.imageType === 'pluginImages') {
if (this.id === 'defaults' && this.imageType === 'contentImages') {
dirPath = path.join(this.siteDir, 'input', 'media', 'posts', 'defaults');
responsiveDirPath = path.join(this.siteDir, 'input', 'media', 'posts', 'defaults', 'responsive');
} else if (this.id === 'defaults' && this.imageType === 'tagImages') {
dirPath = path.join(this.siteDir, 'input', 'media', 'tags', 'defaults');
responsiveDirPath = path.join(this.siteDir, 'input', 'media', 'tags', 'defaults', 'responsive');
} else if (this.id === 'defaults' && this.imageType === 'authorImages') {
dirPath = path.join(this.siteDir, 'input', 'media', 'authors', 'defaults');
responsiveDirPath = path.join(this.siteDir, 'input', 'media', 'authors', 'defaults', 'responsive');
} else if (this.imageType === 'pluginImages') {
dirPath = path.join(this.siteDir, 'input', 'media', 'plugins', this.pluginDir);
} else if (this.id === 'website') {
} else if (this.id === 'website' || this.imageType === 'optionImages') {
dirPath = path.join(this.siteDir, 'input', 'media', 'website');
responsiveDirPath = path.join(this.siteDir, 'input', 'media', 'website', 'responsive');
} else if (this.imageType === 'tagImages' && this.id) {
Expand Down
Loading

0 comments on commit 2379e3c

Please sign in to comment.