Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use wordpress for static pages #10992

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d92e9c0
fetch a page from wp api
4nt0ineB Jul 24, 2024
3b7a83e
wp styles shenanigans
4nt0ineB Jul 24, 2024
c61883b
listing pages
4nt0ineB Jul 25, 2024
125e79d
removed unused env vars
4nt0ineB Jul 26, 2024
9d806d9
content menu
4nt0ineB Jul 26, 2024
148105d
Merge branch 'main' into wp-content-poc
4nt0ineB Jul 26, 2024
f786cc9
style
4nt0ineB Jul 26, 2024
b5c6d5a
breadcrumbs
4nt0ineB Jul 29, 2024
daa7663
style
4nt0ineB Jul 29, 2024
94c6993
docs
4nt0ineB Jul 30, 2024
f42c459
docs
4nt0ineB Jul 30, 2024
ed47650
Update lib/ProductOpener/CMS.pm
4nt0ineB Aug 7, 2024
60a90f7
changed the way of caching page metadata
4nt0ineB Aug 8, 2024
8dd2afe
Merge branch 'main' into wp-content-poc
4nt0ineB Aug 8, 2024
a83607d
style
4nt0ineB Aug 8, 2024
5c89885
docs
4nt0ineB Aug 8, 2024
241941d
docs
4nt0ineB Aug 8, 2024
7ad2c5a
Merge branch 'main' into wp-content-poc
4nt0ineB Aug 8, 2024
090468a
fix routing
4nt0ineB Aug 8, 2024
3733256
css
4nt0ineB Aug 8, 2024
c4b9e92
wide title on content page
4nt0ineB Aug 9, 2024
865522e
Merge branch 'main' into wp-content-poc
4nt0ineB Aug 20, 2024
9a8f1c8
page translation support with WPML
4nt0ineB Aug 20, 2024
95a506d
wordpress page order support
4nt0ineB Aug 20, 2024
80cd35a
fix page order was not scalar
4nt0ineB Aug 20, 2024
2e85fb9
removed some wp.css root css overriding global css
4nt0ineB Aug 20, 2024
5725f52
handle case when wordpress url is not set in env
4nt0ineB Aug 20, 2024
7b8ab67
fix undef values when unable to call api
4nt0ineB Aug 20, 2024
ef9af42
style
4nt0ineB Aug 20, 2024
50a4774
enable redirect in off-web
4nt0ineB Aug 23, 2024
8301909
use a single file for redirections
4nt0ineB Aug 23, 2024
8c01d55
Merge branch 'main' into wp-content-poc
4nt0ineB Aug 23, 2024
afb4303
critic
4nt0ineB Aug 23, 2024
692ceaa
use wordpress posts instead of pages
4nt0ineB Aug 28, 2024
6d48edf
Merge branch 'openfoodfacts:main' into wp-content-poc
4nt0ineB Aug 28, 2024
27774e5
tests results
4nt0ineB Aug 28, 2024
f5cb9b4
Merge branch 'main' into 4nt0ineB/wp-content-poc
alexgarel Nov 7, 2024
f8fe257
build: lint
alexgarel Nov 7, 2024
ed01732
test: Update tests results
Nov 8, 2024
698f940
feat: wordpress contents (WIP)
alexgarel Nov 27, 2024
9dfc53c
ci: Update labeler.yml for the new CMS
teolemon Nov 27, 2024
b3c505f
fix: use utf8 in CMS.pm + re-init data on cms load
alexgarel Nov 28, 2024
221997d
fix: fix tests and fix encodings
alexgarel Nov 28, 2024
825852d
build: fix encoding env in Dockerfile
alexgarel Nov 28, 2024
8223509
Merge branch 'main' into feat-wp-content
alexgarel Nov 28, 2024
b886608
ci: exclude wp.css from stylelint
alexgarel Nov 28, 2024
c332fbb
fix: categories duplicate guyot
alexgarel Nov 29, 2024
9b4a884
Merge branch 'main' into feat-wp-content
alexgarel Nov 29, 2024
f64c512
docs: documentation on wordpress and website contents
alexgarel Nov 29, 2024
d24da16
test: Update tests results
Nov 29, 2024
fb81709
fix: use a constant for content path
alexgarel Dec 12, 2024
7ebd187
chore: take back old contents link, until they are made better
alexgarel Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ ELASTICSEARCH_HOSTS=
LOG_LEVEL_ROOT=TRACE
LOG_LEVEL_MONGODB=TRACE
LOG_LEVEL_RATE_LIMITER=TRACE
# those are for producer platform, to connect to odoo
ODOO_CRM_URL=
ODOO_CRM_DB=
ODOO_CRM_USER=
ODOO_CRM_PASSWORD=
# contents taken from wordpress
WORDPRESS_URL=https://off:[email protected]

# No need to have it running, it's just to compose a URL
# you might also use the .net service
Expand Down
12 changes: 10 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1516,11 +1516,19 @@ Averages by categories:
- any-glob-to-any-file: 'scripts/create_small_categories_nutriments_per_country_for_testing.pl'

# This lives at https://github.com/openfoodfacts/openfoodfacts-web.
# We'd like to use a CMS like wordpress instead.
# Make sure to clone it if you want the content page to work on your local instance.
# We're migrating pages progressively to our Wordpress-based CMS.
# Make sure to clone openfoodfacts-web it if you want the content page to work on your local instance.
# TODO: explain how you should do for Wordpress
Static content:
- changed-files:
- any-glob-to-any-file: 'scripts/copy_text_files.pl'
- any-glob-to-any-file: 'docs/dev/explain-website-contents.md'
- any-glob-to-any-file: 'docs/dev/how-to-setup-wordpress.md'
- any-glob-to-any-file: 'html/css/wp.css'
- any-glob-to-any-file: 'lib/ProductOpener/CMS.pm'
- any-glob-to-any-file: 'templates/web/pages/content/menu.tt.html'
- any-glob-to-any-file: 'templates/web/pages/content/wordpress_content.tt.html'
- any-glob-to-any-file: 'tests/unit/cms.t'

# Matomo is our analytics system. We need to fetch matomo logs from the mobile app to generate scan statistics. We used to do that with server side logs.
# We also want to add Matomo events on the key part of the Web experience (see tracking issue for details)
Expand Down
5 changes: 4 additions & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"no-descending-specificity": null,
"scss/at-extend-no-missing-placeholder": null,
"no-invalid-position-at-import-rule": null
}
},
"ignoreFiles": [
"html/css/wp.css"
]
}
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt set -x && \
liblog-any-adapter-log4perl-perl \
# NB: not available in ubuntu 1804 LTS:
libgeoip2-perl \
libemail-valid-perl
libemail-valid-perl \
# locale
locales
# set locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8
RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt set -x && \
apt install -y \
#
Expand Down
3 changes: 3 additions & 0 deletions cgi/display.pl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
elsif (defined $request_ref->{properties}) {
display_properties($request_ref);
}
elsif (defined $request_ref->{content}) {
display_content($request_ref);
}
elsif (defined $request_ref->{text}) {
if ($request_ref->{text} =~ /^products_stats/) {
display_stats($request_ref);
Expand Down
3 changes: 2 additions & 1 deletion conf/apache-2.4/modperl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ PerlPassEnv RATE_LIMITER_BLOCKING_ENABLED
PerlPassEnv ODOO_CRM_URL
PerlPassEnv ODOO_CRM_DB
PerlPassEnv ODOO_CRM_USER
PerlPassEnv ODOO_CRM_PASSWORD
PerlPassEnv ODOO_CRM_PASSWORD
PerlPassEnv WORDPRESS_URL
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ x-backend-conf: &backend-conf
- ODOO_CRM_DB
- ODOO_CRM_USER
- ODOO_CRM_PASSWORD
- WORDPRESS_URL
depends_on:
- memcached
volumes:
Expand Down
58 changes: 58 additions & 0 deletions docs/dev/explain-website-contents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Explain Website Contents

The Open Food Facts site has content pages that explain the project and its goals,
or give explanations on important topics.

Those contents comes from two sources:

* the openfoodfacts-web repository
* an external CMS, which is an instance WordPress

## CMS Pages

The pages from the CMS are the new way of creating content.
They offer an easy to use interface to create and edit content, for non technical users.

Note: We don't use pages but posts, because they have tags
which can be used to filter the pages according to the Product Opener instance.

We use the WPML plugin to enable internationalization and translation of pages.
WPML is connected to crowdin so that we can have our community translate the contents.

We talk to the WordPress API to get the content of the pages.
At startup, `load_data`, calls `load_cms_data`
which will use the API to get the known pages with some metadata.

A special URL, available to administrators, `/content/refresh`
can be used to call `load_cms_data` again, and refresh the pages list.


### Crowdin / WPML integration

See [How to setup wordpress](./how-to-setup-wordpress.md)

### How to create a page

See https://wiki.openfoodfacts.org/Open_Food_Facts_Contents

## openfoodfacts-web Pages

This is the historic way of creating contents, and is still used for some pages.
As contents are reworked, we should try to use the CMS pages.

The contents are html files in the `openfoodfacts-web` repository, under the `lang/xx/texts` folders.

This repository also contains translations for emails, or additives and will remain valid for those specific contents.

Because it uses plain html files, it is complicated for non technical users to edit the contents.

The integration with crowdin is done through the usual github / crowdin workflow.

### Connecting pages to the website

See [How to use pages from openfoodfacts-web](./how-to-use-pages-from-openfoodfacts-web.md)


## How to migrate from openfoodfacts-web to the CMS

See https://wiki.openfoodfacts.org/Open_Food_Facts_Contents#How_to:_replace_an_Openfoodfacts-web_page_by_a_Wordpress_page_.28Not_yet_in_production.29
89 changes: 89 additions & 0 deletions docs/dev/how-to-setup-wordpress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# How to setup wordpress for contents

We use a WordPress instance to manage the contents of the site.
See [Explain Website contents](./explain-website-contents.md)

## Install WPGraphQL extension

Install https://wordpress.org/plugins/wp-graphql/
for Product Opener will use the GraphQL API to get the contents.

## Install WPML extension

This is a plugin to manage translations of contents.
It is not free, but has the advantage to be integrated with crowdin,
and to have more advanced features than PolyLang.

Install WPML media translations and WPML Multilingual CMS extensions.

We also install the WPML GraphQL extension.

## WPML configuration

In *WPML* menu, *settings submenu*, *Taxonomies Translations*, tell that Tags and Categories are not translatable.

## Connect WPML to crowdin

We asked Crowdin for an account as an Open Source Project to be able to have more than one project.

This is needed because WPML does not use same id for languages as Crowdin,
and it's quite impossible to change the code on WPML side,
so we will need to map the languages in a specific way in the Crowdin project.

In crowdin, I used the *openfoodfacts* account (linked to *tech* email address).

I created the *openfoodfacts-contents* project, copying languages from the *openfoodfacts* project. And using advanced tab, I also used the same glossary and memory translation.

Then go to the store, and install the [WPML app](https://store.crowdin.com/wpml-app).

I installed it to the *openfoodfacts-contents* project.

Go to *openfoodfacts-contents* project, in *integrations* tab, click on *create token*, and copy the token value.

In the configuration of WPML, go to the *Translation management* menu, *Translators* tab and activate Crowdin.
In the Crowdin box, click on *authenticate* button and paste the token value, then submit.

Also use the "Refresh Language pairs" button.

## Setting up languages

In Wordpress, go to the *WPML, Languages* sub menu, and add languages.
I added all but Macedonian which is not supported by crowdin out of the box.


We have some differences between default WPML langage codes, that we have to setup by ourselves.
I saw that by trying to send my first batch of translations to crowdin ([see below](#test-sending-translations))

We log into Crowdin, go in the *openfoodfacts-contents* project, *settings*,
*languages* sub menu, then click on *Add custom language codes*
and change the *locale* for:
- Spanish -> es
- Irish -> ga
- Armenian -> hy
- Punjab -> pa
- Portugese -> pt-pt
- Portugese, Brazilian -> pt-br
- Swedish -> sv
- Chinese Simplified -> zh-hans
- Chinese Traditional -> zh-hant
- Nepali -> ne
- Urdu (India) -> ur

## Test sending translations

Go to *WPML* menu, *Translation Management* sub menu, *Dashboard* tab.
Select an article, and all languages.

Then chose on the *Assign to translator*, and click *Add to translation Basket*.

Then go to the *Translation Basket* tab, set a batch name and timeline,
verify all contents are set to *Crowdin* as translator, and click on "Send all items for translation".

If you got problems, you may look at the *communication log* (link at the bottom of the page).

```
11/27/2024 10:59:59 am - error - (27) Crowdin doesn't support the following language pair: en -> es,ga,hy,mk,ne,pa,pt-pt,pt-br,sv,ur,zh-hans,zh-hant.<br />Please <a href='https://crowdin.com/'>contact Crowdin</a> and ask them to add mapping for en to es,ga,hy,mk,ne,pa,pt-pt,pt-br,sv,ur,zh-hans,zh-hant, so they can receive this job. You can send them this email:<br /><i>Dear Crowdin,<br />I wanted to let you know that you're currently not supporting en to es,ga,hy,mk,ne,pa,pt-pt,pt-br,sv,ur,zh-hans,zh-hant which I am hoping to use on my website.<br />Could you update the configuration to ensure it works for me in the future?<br />Regards</i>
```

After searching a bit if I could do change the code on WPML side, which was not possible,
I fixed it by changing language mappings in Crowdin projects (and that's why it's a separate project from the main one).
Loading
Loading