Skip to content

Commit

Permalink
Merge branch 'master' into linkcheck-2023-05-10
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepiercy authored May 10, 2023
2 parents 616a816 + 166e269 commit e0beb32
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 51 deletions.
71 changes: 70 additions & 1 deletion docs/source/recipes/express.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,75 @@ if (__SERVER__) {
Now the [test-middleware](http://localhost:3000/test-middleware) page can be
visited and it will return the simple string and not the usual Volto pages.

## Static middleware

The `staticMiddleware` is for serving static files such as style sheets and client-side JavaScript files from the `BUILD_DIR/PUBLIC` or `PUBLIC_DIR` directory.
It uses the `express.static()` function to serve static files, and the `setHeaders()` function to add response headers to the files that it serves.

```js
import { settings as defaultSettings } from '@plone/volto/config';
import express from 'express';

const settings = { ...defaultSettings };
if (__SERVER__) {
const customStaticMiddleware = express.static('test/static/files');

function setCustomHeaders(req, res, next) {
res.setHeader('Cache-Control', 'public, max-age=3600');
next();
}

customStaticMiddleware.setHeaders = setCustomHeaders;
customStaticMiddleware.id = 'custom-static-middleware';

settings.expressMiddleware = [
...defaultSettings.expressMiddleware,
customStaticMiddleware,
];
}
```

### Function `setHeaders(path)`

The `setHeaders()` function is used to update the response headers for a file.
It takes the path of the file being served as an argument, and adds the response headers to that file.
It uses the `config` object specified in `config.settings.serverConfig.staticFiles` to determine which response headers should be added to the file.

### Configuration

The `config.settings.staticFiles` is an array of objects with three properties:

`id`
: a string identifier for the static file rule

`match`
: a regular expression that evaluates the path of the requested resource

`headers`
: an object containing the headers added if the match is successful

The following example shows how to add the response header `Cache-Control: public, max-age=3600` to a file named {file}`styles.css` located in the `BUILD_DIR/PUBLIC` directory:

```js
import {
settings as defaultSettings,
} from '@plone/volto/config';

const settings = { ...defaultSettings };
settings.staticFiles = [
...defaultSettings.staticFiles, {
id: 'styles_css',
match: /^\/styles\.css$/,
headers: {
'Cache-Control': 'public, max-age=3600',
},
}
]
```

The rules are checked in sequential order, and the search stops at the first match.
The default rules add headers that set the browser cache to 365 days for resources under the `/static` path and 60 seconds for all other paths.

Notice the use of the ``__SERVER__`` condition. Because the code in a Volto
project's ``config.js`` gets executed by both the server and the client
(browser), the server-side libraries need to "excluded" with conditions.
Expand All @@ -54,4 +123,4 @@ See [ExpressJS](https://expressjs.com/) website for more documentation.
```{note}
Addon authors should add the ``id`` property to the middleware so that it
can be identified and manipulated in Volto projects configuration.
```
```
1 change: 1 addition & 0 deletions news/4518.documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added documentation regarding the static middleware. @BhardwajAditya-github
2 changes: 2 additions & 0 deletions news/4567.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Change conditional checking to optional chaining for a theme icon @nilootpal

Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# Translation of plone.pot to German
# Jan Ulrich Hasecke <jan.ulrich@hasecke.com>, 2003-2010.
# Simon Eisenmann <simon@struktur.de>, 2003.
# Hanno Schlichting <plone@hannosch.info>, 2003-2008.
# Dominik Bittl <dominik@umount.org>, 2005.
# Christian Ullrich <chris@chrullrich.de>, 2005.
# Thomas Lotze <tl@gocept.com>, 2005-2008.
# Sven Deichmann <deichmann@werkbank.com>, 2008-2010.
# Harald Friessnegger <harald@webmeisterei.com>, 2011.
# Andreas Jung <info@zopyx.com>, 2012
# Translation of volto.pot to German
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Gettext Message File for Plone
# Translators:
# Leonardo J. Caballero G. <leonardocaballero@gmail.com>, 2019.
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
Expand All @@ -20,3 +17,5 @@ msgstr ""
"Preferred-Encodings: utf-8\n"
"Domain: volto\n"
"X-Is-Fallback-For: es-ar es-bo es-cl es-co es-cr es-do es-ec es-es es-sv es-gt es-hn es-mx es-ni es-pa es-py es-pe es-pr es-us es-uy es-ve\n"


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Translation of plone.pot to EU
# Translation of volto.pot to EU
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
Expand All @@ -15,3 +15,5 @@ msgstr ""
"Language-Code: eu\n"
"Language-Name: eu\n"
"Preferred-Encodings: utf-8 latin1\n"


Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# Translation of plone.pot to French
# French Translation Team <plone-i18n@lists.sourceforge.net>, 2003-2006.
# Sebastien Douche <sdouche@gmail.com>, 2005-2007.
# Encolpe Degoute <encolpe.degoute@ingeniweb.com>, 2006, 2007, 2008.
# Gilles Lenfant <gilles.lenfant@ingeniweb.com>, 2008.
# Encolpe Degoute <encolpe@gmail.com>, 2008.
# Vincent Fretin <vincent.fretin@gmail.com>, 2009.
# Kevin Deldycke <kevin@deldycke.com>, 2009.
# JeanMichel FRANCOIS <toutpt@gmail.com>, 2010.
# Denis Bitouzé <denis.bitouze@univ-littoral.fr>, 2019.
# Translation of volto.pot to French
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
Expand All @@ -25,3 +16,5 @@ msgstr ""
"Language-Name: French\n"
"Preferred-Encodings: utf-8 latin1\n"
"X-Is-Fallback-For: fr-be fr-ca fr-lu fr-mc fr-ch fr-fr\n"


Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ msgstr ""
"Content-Type: \n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"


Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Manabu TERADA <terada@cmscom.jp> 2019
# Peacock <peacock0803sz@gmail.com> 2019
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
Expand All @@ -17,3 +15,5 @@ msgstr ""
"Language-Name: Japanese\n"
"Preferred-Encodings: utf-8\n"
"X-Is-Fallback-For: ja-jp\n"


Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# Translators:
# Fred van Dijk <info@zestsoftware.nl>, 2016
# Coen van der Kamp <c.van.der.kamp@zestsoftware.nl>, 2015
# Danny Bloemendaal <danny.bloemendaal@informaat.nl>, 2007
# Diederik Veeze <diederik_24@hotmail.com>, 2015
# Duco Dokter <dokter@w20e.com>, 2007
# Esther Ladage <e.ladage@zestsoftware.nl>, 2005
# Jean-Paul Ladage <j.ladage@zestsoftware.nl>, 2017
# Kees Hink <hink@gw20e.com>, 2010
# Maarten Kling <maarten@fourdigits.nl>, 2013
# Mark van Lent <m.vanlent@zestsoftware.nl>, 2007
# Mirella van Teulingen <m.van.teulingen@zestsoftware.nl>, 2005
# Reinout van Rees <reinout@zestsoftware.nl>, 2008
# Roel Bruggink <roel@fourdigits.nl>, 2009
# Wietze Helmantel <helmantel@goldmund-wyldebeast-wunderliebe.com>, 2007
msgid ""
msgstr ""
"Project-Id-Version: PlonenPOT-Creation-Date: 2017-04-27T19:30:59.079Z\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Translators:
# Emanuel de Jesus <emanuel.angelo@gmail.com>, 2019
#
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
Expand All @@ -18,3 +15,5 @@ msgstr ""
"Language-Code: pt\n"
"Language-Name: Portuguese\n"
"Preferred-Encodings: utf-8\n"


Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Translators:
# Léu Almeida <leo@webid.net.br>, 2019
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
Expand All @@ -16,3 +14,5 @@ msgstr ""
"Language-Code: pt-br\n"
"Language-Name: Português do Brasil\n"
"Preferred-Encodings: utf-8\n"


Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Translation of plone.pot to Romanian
# Alin Voinea <avoinea@plone.org>, 2020.
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ msgstr ""
"Language-Name: English\n"
"Preferred-Encodings: utf-8\n"
"Domain: volto\n"


1 change: 1 addition & 0 deletions packages/generator-volto/news/4737.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix whitespace in empty locales created by the generator. @davisagli
4 changes: 2 additions & 2 deletions src/components/theme/Icon/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const Icon = ({
ariaHidden,
}) => (
<svg
xmlns={name.attributes && name.attributes.xmlns}
viewBox={name.attributes && name.attributes.viewBox}
xmlns={name?.attributes?.xmlns}
viewBox={name?.attributes?.viewBox}
style={{
height: size,
width: 'auto',
Expand Down

0 comments on commit e0beb32

Please sign in to comment.