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

[FEATURE] Génération statique de pix-site #201

Merged
merged 17 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .buildpacks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/Scalingo/nodejs-buildpack
https://github.com/Scalingo/nginx-buildpack

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
nginx.conf
HEYGUL marked this conversation as resolved.
Show resolved Hide resolved

# Runtime data
pids
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,27 @@ Exemples :
Le contenu d'une slice est passé *en entier* et tel-quel au composant Vue équivalent via une propriété exposée `:slice`.

For detailed explanation on how things work, check out [Nuxt.js docs](https://nuxtjs.org).

### NGINX

Pour tester la configuration NGINX des sites statiques en local, il suffit de faire:

```
npm run build:site

PORT=80 erb servers.conf.erb > nginx.conf && docker-compose up
```

Aller sur `http://localhost` ou `http://localhost.org`
HEYGUL marked this conversation as resolved.
Show resolved Hide resolved

Pour que localhost.org soit fonctionnel, il faut éditer votre fichier `/etc/hosts` en y ajoutant la ligne suivante :
```
127.0.0.1 localhost.org
```

Des tests unitaires existent dans `tests.sh`.
Pour les lancer il faut exécuter la commande:

```
bash tests.sh
```
12 changes: 1 addition & 11 deletions components/LanguageDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<template>
<div
v-if="
nonFrenchFranceLocales.length > 1 &&
$config.languageSwitchEnabled &&
domainAllowsLanguageSwitch
"
class="language-dropdown"
>
<div class="language-dropdown">
<dropdown-button
:options="options"
:selected="currentLanguage"
Expand Down Expand Up @@ -49,9 +42,6 @@ export default {
(locale) => locale.lang !== this.currentLocale
)
},
domainAllowsLanguageSwitch() {
return this.$store.state.host === this.$config.orgDomain
},
},
methods: {
languageDidChange(selectedLocale) {
Expand Down
25 changes: 0 additions & 25 deletions components/NavigationDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,6 @@ export default {
default: null,
},
},
data() {
return {
eventListener: (event) => {
if (
event.target.getAttribute('dropdown-index') !== this.dropdownIndex
) {
this.closeDropdown()
}
},
}
},
mounted() {
const page = document.getElementsByTagName('body')[0]
page.addEventListener('click', this.eventListener)
},
beforeDestroy() {
const page = document.getElementsByTagName('body')[0]
page.removeEventListener('click', this.eventListener)
},

methods: {
closeDropdown() {
this.$emit('closeNavigationDropdown', this.dropdownIndex)
},
},
}
</script>

Expand Down
6 changes: 5 additions & 1 deletion components/OrganizationNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export default {
},
computed: {
showLanguageDropdown() {
return this.$config.languageSwitchEnabled
return (
process.env.isPixSite &&
this.$config.languageSwitchEnabled &&
this.$i18n.locale !== 'fr-fr'
)
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions components/PixLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export default {

if (this.field.link_type === 'Document') {
template = `
<router-link to="${this.localePath(url)}">
<router-link to="${this.localePath(url)}" exact>
HEYGUL marked this conversation as resolved.
Show resolved Hide resolved
<slot/>
</router-link>
`
} else if (relativeLinkPrefix) {
const relativeUrl = url.replace(relativeLinkPrefix, '')
const relativeUrl = url.replace(relativeLinkPrefix, '/')
template = `
<router-link to="${this.localePath(relativeUrl)}">
<router-link to="${this.localePath(relativeUrl)}" exact>
<slot/>
</router-link>
`
Expand All @@ -57,9 +57,9 @@ function getRelativeLinkPrefix(url) {
}
let defaultPrefixes
if (process.env.isPixPro) {
defaultPrefixes = 'https://pro.pix.fr'
defaultPrefixes = 'https://pro.pix.fr/'
} else {
defaultPrefixes = 'https://pix.org,https://pix.fr'
defaultPrefixes = 'https://pix.org/,https://pix.fr/'
}
const relativeLinkPrefixes = (
process.env.RELATIVE_LINK_PREFIXES || defaultPrefixes
Expand Down
29 changes: 18 additions & 11 deletions components/slices/NavigationZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
@click.stop.prevent
>
{{ menuItem.name }}
<fa v-if="showDropdown(`${index}`)" icon="angle-up" />
<fa v-if="isOpenDropdown(`${index}`)" icon="angle-up" />
<fa v-else icon="angle-down" />
</button>
<navigation-dropdown
v-if="showDropdown(`${index}`)"
v-show="isOpenDropdown(`${index}`)"
type="button"
:options="menuItem.subNavigationLinks"
:dropdown-index="`${index}`"
@closeNavigationDropdown="toggleDropdown(`${index}`)"
>
</navigation-dropdown>
</div>
Expand All @@ -33,7 +32,6 @@
</template>

<script>
import Vue from 'vue'
import NavigationDropdown from '@/components/NavigationDropdown'

export default {
Expand All @@ -49,7 +47,7 @@ export default {
},
data() {
return {
dropdownMap: {},
openDropdownIndex: undefined,
}
},
computed: {
Expand All @@ -66,15 +64,24 @@ export default {
return navigation.links
},
},
mounted() {
const page = document.getElementsByTagName('body')[0]
page.addEventListener('click', this.toggleDropdown)
},
beforeDestroy() {
const page = document.getElementsByTagName('body')[0]
page.removeEventListener('click', this.toggleDropdown)
},
methods: {
showDropdown(dropdownIndex) {
if (!this.dropdownMap[dropdownIndex]) {
Vue.set(this.dropdownMap, dropdownIndex, false)
}
return this.dropdownMap[dropdownIndex]
isOpenDropdown(dropdownIndex) {
return this.openDropdownIndex === dropdownIndex
},
toggleDropdown(dropdownIndex) {
Vue.set(this.dropdownMap, dropdownIndex, !this.dropdownMap[dropdownIndex])
if (this.isOpenDropdown(dropdownIndex)) {
this.openDropdownIndex = undefined
} else {
this.openDropdownIndex = dropdownIndex
}
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion components/slices/PageBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default {
this.$modal.show('videoModal')
},
isVideo(link) {
return link.banner_link_url.url.includes('pix-videos/')
return link?.['banner_link_url']?.url?.includes('pix-videos/')
HEYGUL marked this conversation as resolved.
Show resolved Hide resolved
},
videoClass(link) {
return this.isVideo(link)
Expand Down
12 changes: 6 additions & 6 deletions components/slices/PageSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ export default {
},
computed: {
paragraphs() {
return this.slice.items
return this.slice?.items
bpetetot marked this conversation as resolved.
Show resolved Hide resolved
},
title() {
return this.slice.primary.title
return this.slice?.primary?.title
},
image() {
return this.slice.primary.logo
return this.slice?.primary?.logo
},
description() {
return this.slice.primary.description
return this.slice?.primary?.description
},
buttonLink() {
return this.slice.primary.button_link
return this.slice?.primary?.['button_link']
},
buttonText() {
return this.slice.primary.button_title
return this.slice?.primary?.['button_title']
},
hasImage() {
return this.image && this.image.url
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'
services:
nginx:
image: nginx:latest
container_name: production_nginx
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- ./dist:/app/dist
ports:
- 80:80
13 changes: 13 additions & 0 deletions middleware/current-page-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Middleware computes og:url for meta tags (SEO)
export default function (context) {
const { app, route } = context
const host = getHost(app.i18n.locale)
context.currentPagePath = `${host}${route.path}`
}

function getHost(locale) {
if (process.env.isPixSite) {
return locale === 'fr-fr' ? 'https://pix.fr' : 'https://pix.org'
}
return 'https://pro.pix.fr'
}
9 changes: 0 additions & 9 deletions middleware/pix-pro/current-page-path.js

This file was deleted.

7 changes: 0 additions & 7 deletions middleware/pix-pro/redirect-to-external-link.js

This file was deleted.

10 changes: 0 additions & 10 deletions middleware/pix-site/current-page-path.js

This file was deleted.

7 changes: 0 additions & 7 deletions middleware/pix-site/redirect-to-external-link.js

This file was deleted.

38 changes: 23 additions & 15 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { transports } from 'winston'

export default {
mode: 'universal',
target: 'static',
publicRuntimeConfig: {
languageSwitchEnabled: process.env.LANGUAGE_SWITCH_ENABLED || false,
orgDomain: process.env.DOMAIN_ORG || 'pix.org',
Expand All @@ -15,7 +16,6 @@ export default {
},
dir: {
pages: `pages/${process.env.SITE}`,
middleware: `middleware/${process.env.SITE}`,
},
/*
** Headers of the page
Expand Down Expand Up @@ -127,20 +127,28 @@ export default {
axios: {},
i18n: {
defaultLocale: 'fr-fr',
locales: [
{
code: 'fr-fr',
file: 'fr-fr.js',
},
{
code: 'fr',
file: 'fr.js',
},
{
code: 'en-gb',
file: 'en-gb.js',
},
],
locales:
process.env.SITE === 'pix-pro'
? [
{
code: 'fr-fr',
file: 'fr-fr.js',
},
]
: [
{
code: 'fr-fr',
file: 'fr-fr.js',
},
{
code: 'fr',
file: 'fr.js',
},
{
code: 'en-gb',
file: 'en-gb.js',
},
],
lazy: true,
langDir: 'lang/',
vueI18n: {
Expand Down
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
},
"scripts": {
"clean": "rm -rf node_modules .nuxt",
"build": "nuxt build && npm run signal-github",
"start": "nuxt start",
"build": "nuxt build && nuxt export && npm run signal-github",
"start": "nuxt serve",
"dev:site": "SITE=pix-site nuxt",
"build:site": "SITE=pix-site nuxt build",
"start:site": "SITE=pix-site nuxt start",
"build:site": "SITE=pix-site nuxt build && nuxt export",
"dev:pro": "SITE=pix-pro nuxt",
"build:pro": "SITE=pix-pro nuxt build",
"start:pro": "SITE=pix-pro nuxt start",
"build:pro": "SITE=pix-pro nuxt build && nuxt export",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"test": "SITE=pix-site jest --no-coverage",
"release": "npm run release:minor",
Expand Down
7 changes: 0 additions & 7 deletions pages/pix-pro/employers.vue → pages/pix-pro/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ import KeyNumbers from '~/components/slices/KeyNumbers'

export default {
name: 'Employers',
nuxtI18n: {
paths: {
fr: '/employeurs',
'fr-fr': '/employeurs',
'en-gb': '/employers',
},
},
components: { HeroBanner, KeyNumbers, SectionColumnSlice, SectionSlice },
async asyncData({ app, error, req, currentPagePath }) {
try {
Expand Down
Loading