Skip to content

Commit

Permalink
add prefix-path express-middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 authored and wesleybl committed Jul 7, 2023
1 parent f48eaef commit 5c387dd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/volto-slate/src/editor/plugins/Image/render.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { useSelected, useFocused } from 'slate-react';
import { Image } from '@plone/volto/components';

export const ImageElement = (props) => {
const { attributes, children, element } = props;
Expand All @@ -16,7 +17,7 @@ export const ImageElement = (props) => {
return (
<span {...attributes} style={{ display: 'inline-block' }}>
{children}
<img alt="" src={element.url} style={style} />
<Image alt="" src={element.url} style={style} />
</span>
);
};
16 changes: 4 additions & 12 deletions packages/volto-slate/src/editor/plugins/StyleMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ import './style.less';

export default function install(config) {
const { slate } = config.settings;
slate.styleMenu = slate.styleMenu || {};
slate.styleMenu.inlineStyles = slate.styleMenu.inlineStyles || [];

slate.styleMenu.inlineStyles = [
{
cssClass: 'cool-inline-text',
label: 'Cool Inline Text',
},
];
slate.styleMenu.blockStyles = [];
slate.buttons.styleMenu = (props) => <StyleMenu {...props} title="Styles" />;

slate.toolbarButtons.push('styleMenu');
slate.expandedToolbarButtons.push('styleMenu');

// slate.styleMenu = {
// blockStyles: [],
// };
slate.styleMenu = {
inlineStyles: [],
blockStyles: [],
};

return config;
}
3 changes: 2 additions & 1 deletion src/components/theme/Widgets/ImageWidget.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import cx from 'classnames';
import { flattenToAppURL } from '@plone/volto/helpers';
import { Image } from '@plone/volto/components';

const niceBytes = (bytes) => {
bytes = Number(bytes);
Expand All @@ -18,7 +19,7 @@ const niceBytes = (bytes) => {
const ImageWidget = ({ value, className }) =>
value ? (
<span className={cx(className, 'image', 'widget')}>
<img
<Image
src={
value.data
? `data:${value['content-type']};base64,${value.data}`
Expand Down
2 changes: 2 additions & 0 deletions src/config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import robotstxtMiddleware from '@plone/volto/express-middleware/robotstxt';
import sitemapMiddleware from '@plone/volto/express-middleware/sitemap';
import staticsMiddleware from '@plone/volto/express-middleware/static';
import devProxyMiddleware from '@plone/volto/express-middleware/devproxy';
import prefixPathMiddleware from '@plone/volto/express-middleware/prefixPath';

const settings = {
expressMiddleware: [
devProxyMiddleware(),
prefixPathMiddleware(),
filesMiddleware(),
imagesMiddleware(),
robotstxtMiddleware(),
Expand Down
19 changes: 19 additions & 0 deletions src/express-middleware/prefixPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express from 'express';
import config from '@plone/volto/registry';

export const prefixPath = function (req, res, next) {
// Re-direct to /prefix-path for all root calls
if (config.settings.prefixPath) {
res.redirect(config.settings.prefixPath);
} else {
next();
}
};

export default function () {
const middleware = express.Router({ strict: true });

middleware.get('/', prefixPath);
middleware.id = 'prefixPath';
return middleware;
}

0 comments on commit 5c387dd

Please sign in to comment.