Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(export): ajoute le rel=canonical lors de la preview
Browse files Browse the repository at this point in the history
thom4parisot committed Jan 21, 2025
1 parent 9d2d6d4 commit 8f56961
Showing 10 changed files with 183 additions and 150 deletions.
81 changes: 41 additions & 40 deletions .github/workflows/deploy-tag.yml
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@ name: Ansible deploy production
run-name: Deploy version ${{ inputs.release-version }} on production by @${{ github.actor }}

on:
# workflow_run:
# workflows:
# - "Build and deploy Docker images"
# types:
# - completed
# workflow_run:
# workflows:
# - "Build and deploy Docker images"
# types:
# - completed
workflow_dispatch:
inputs:
release-version:
@@ -21,6 +21,7 @@ env:
SNOWPACK_PUBLIC_HUMAN_ID_REGISTER_ENDPOINT: https://humanid.huma-num.fr/register?service=https://stylo.huma-num.fr/authorization-code/callback
SNOWPACK_MATOMO_URL: https://analyseweb.huma-num.fr/
SNOWPACK_MATOMO_SITE_ID: 286
SNOWPACK_PUBLIC_ANNOTATIONS_CANONICAL_BASE_URL: https://stylo.ecrituresnumeriques.ca
SENTRY_DSN: https://276d5080680a70a3edf98783a2b264d0@o4507130700496896.ingest.de.sentry.io/4507130704560208
SENTRY_ENVIRONMENT: prod

@@ -59,44 +60,44 @@ jobs:
url: https://stylo.huma-num.fr

steps:
- uses: actions/checkout@v4
with:
ref: ${{ format('v{0}', inputs.release-version) }}
- uses: actions/checkout@v4
with:
ref: ${{ format('v{0}', inputs.release-version) }}

- uses: actions/download-artifact@v4
id: assets
with:
name: front-assets
path: /tmp/front-assets
- uses: actions/download-artifact@v4
id: assets
with:
name: front-assets
path: /tmp/front-assets

- name: Set up Python 3.10 (w/ cache)
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: '**/deploy-requirements.txt'
- name: Set up Python 3.10 (w/ cache)
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: '**/deploy-requirements.txt'

- name: Install dependencies
run: |
python -m pip install -r .github/workflows/deploy-requirements.txt
- name: Install dependencies
run: |
python -m pip install -r .github/workflows/deploy-requirements.txt
- name: Set Ansible config secrets
run: |
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD_PROD }}" > infrastructure/.ansible-vault-password
- name: Set Ansible config secrets
run: |
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD_PROD }}" > infrastructure/.ansible-vault-password
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY_PROD }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY_PROD }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
- name: Run playbook
working-directory: ./infrastructure
run: |
ansible-playbook -v -i inventories/prod \
--extra-vars "@vault-prod.yml" \
--extra-vars "app_version=${{ inputs.release-version }}" \
--extra-vars "assets_path=/tmp/front-assets/" \
--private-key ~/.ssh/id_ed25519 \
--vault-password-file ./.ansible-vault-password \
playbook.yml
- name: Run playbook
working-directory: ./infrastructure
run: |
ansible-playbook -v -i inventories/prod \
--extra-vars "@vault-prod.yml" \
--extra-vars "app_version=${{ inputs.release-version }}" \
--extra-vars "assets_path=/tmp/front-assets/" \
--private-key ~/.ssh/id_ed25519 \
--vault-password-file ./.ansible-vault-password \
playbook.yml
79 changes: 40 additions & 39 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ name: Ansible deploy dev
on:
workflow_run:
workflows:
- "Build and deploy Docker images"
- 'Build and deploy Docker images'
branches:
- main
- master
@@ -19,6 +19,7 @@ env:
SNOWPACK_PUBLIC_HUMAN_ID_REGISTER_ENDPOINT: https://auth-test.huma-num.fr/register?service=https://stylo-dev.huma-num.fr/authorization-code/callback
SNOWPACK_MATOMO_URL: https://analyseweb.huma-num.fr/
SNOWPACK_MATOMO_SITE_ID: 286
SNOWPACK_PUBLIC_ANNOTATIONS_CANONICAL_BASE_URL: https://stylo.ecrituresnumeriques.ca
SENTRY_DSN: https://276d5080680a70a3edf98783a2b264d0@o4507130700496896.ingest.de.sentry.io/4507130704560208
SENTRY_ENVIRONMENT: dev

@@ -59,41 +60,41 @@ jobs:
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}

steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
id: assets
with:
name: front-assets
path: /tmp/front-assets

- name: Set up Python 3.10 (w/ cache)
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: '**/deploy-requirements.txt'

- name: Install dependencies
run: |
python -m pip install -r .github/workflows/deploy-requirements.txt
- name: Set Ansible config secrets
run: |
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD_DEV }}" > infrastructure/.ansible-vault-password
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY_DEV }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
- name: Run playbook
working-directory: ./infrastructure
run: |
ansible-playbook -v -i inventories/dev \
--extra-vars "@vault-dev.yml" \
--extra-vars "assets_path=/tmp/front-assets/" \
--private-key ~/.ssh/id_ed25519 \
--vault-password-file ./.ansible-vault-password \
playbook.yml
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
id: assets
with:
name: front-assets
path: /tmp/front-assets

- name: Set up Python 3.10 (w/ cache)
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: '**/deploy-requirements.txt'

- name: Install dependencies
run: |
python -m pip install -r .github/workflows/deploy-requirements.txt
- name: Set Ansible config secrets
run: |
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD_DEV }}" > infrastructure/.ansible-vault-password
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY_DEV }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
- name: Run playbook
working-directory: ./infrastructure
run: |
ansible-playbook -v -i inventories/dev \
--extra-vars "@vault-dev.yml" \
--extra-vars "assets_path=/tmp/front-assets/" \
--private-key ~/.ssh/id_ed25519 \
--vault-password-file ./.ansible-vault-password \
playbook.yml
9 changes: 5 additions & 4 deletions front/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ module.exports = {
},
overrides: [
{
files: ["**/*.json", "**/*.json5", "**/*.jsonc"],
parser: "jsonc-eslint-parser",
files: ['**/*.json', '**/*.json5', '**/*.jsonc'],
parser: 'jsonc-eslint-parser',
},
],
plugins: ['react', 'vitest'],
@@ -32,11 +32,12 @@ module.exports = {
APP_VERSION: true,
APP_ENVIRONMENT: true,
SENTRY_DSN: true,
__ANNOTATIONS_CANONICAL_BASE_URL__: true,
__BACKEND_ENDPOINT__: true,
__GRAPHQL_ENDPOINT__: true,
__PROCESS_ENDPOINT__: true,
__PANDOC_EXPORT_ENDPOINT__: true,
__HUMANID_REGISTER_ENDPOINT__: true
__HUMANID_REGISTER_ENDPOINT__: true,
},
rules: {
'react/prop-types': ['warn'],
@@ -46,6 +47,6 @@ module.exports = {
'jsonc/key-spacing': ['error'],
'jsonc/no-irregular-whitespace': ['error'],
'jsonc/object-curly-newline': ['error'],
'jsonc/object-property-newline': ['error']
'jsonc/object-property-newline': ['error'],
},
}
8 changes: 8 additions & 0 deletions front/src/components/Preview.jsx
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom'
import { Loading } from '@geist-ui/core'
import { useStyloExportPreview } from '../hooks/stylo-export.js'
import useGraphQL from '../hooks/graphql.js'
import { applicationConfig } from '../config.js'

import * as queries from './Preview.graphql'

@@ -78,6 +79,12 @@ const strategies = new Map([

export default function Preview({ strategy: strategyId }) {
const { id, version, workspaceId } = useParams()
const { canonicalBaseUrl } = applicationConfig
const canonicalUrl = canonicalBaseUrl
? `${canonicalBaseUrl}/api/v1/${
strategyId === 'article' ? 'htmlArticle' : 'htmlBook'
}/${id}?preview=true`
: null

const strategy = useMemo(
() => strategies.get(strategyId),
@@ -140,6 +147,7 @@ export default function Preview({ strategy: strategyId }) {
<>
<meta name="robots" content="noindex, nofollow" />
<title>{strategy.title(data)}</title>
{canonicalUrl && <link rel="canonical" href={canonicalUrl} />}
<section dangerouslySetInnerHTML={{ __html }} />
</>
)
1 change: 1 addition & 0 deletions front/src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// variables defined statically via vite.config.js
export const applicationConfig = {
backendEndpoint: __BACKEND_ENDPOINT__,
canonicalBaseUrl: __ANNOTATIONS_CANONICAL_BASE_URL__,
graphqlEndpoint: __GRAPHQL_ENDPOINT__,
processEndpoint: __PROCESS_ENDPOINT__,
pandocExportEndpoint: __PANDOC_EXPORT_ENDPOINT__,
66 changes: 42 additions & 24 deletions front/vite.config.js
Original file line number Diff line number Diff line change
@@ -8,9 +8,13 @@ import graphql from '@rollup/plugin-graphql'

// https://vitejs.dev/config/
export default defineConfig(async ({ mode }) => {
const env = loadEnv(mode, fileURLToPath(import.meta.resolve('..')), ['SNOWPACK_', 'SENTRY_'])
const env = loadEnv(mode, fileURLToPath(import.meta.resolve('..')), [
'SNOWPACK_',
'SENTRY_',
])
const { SNOWPACK_MATOMO_URL, SNOWPACK_MATOMO_SITE_ID } = env
const sourcemap = Boolean(env.ENABLE_SOURCEMAPS) || env.SENTRY_ENVIRONMENT === 'dev' || false
const sourcemap =
Boolean(env.ENABLE_SOURCEMAPS) || env.SENTRY_ENVIRONMENT === 'dev' || false

return {
base: env.DEPLOY_PRIME_URL ?? '/',
@@ -21,41 +25,53 @@ export default defineConfig(async ({ mode }) => {
rollupOptions: {
output: {
manualChunks: {
writer: ['monaco-editor', 'y-monaco', '@monaco-editor/react', '@rjsf/core']
}
}
}
writer: [
'monaco-editor',
'y-monaco',
'@monaco-editor/react',
'@rjsf/core',
],
},
},
},
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler'
}
}
api: 'modern-compiler',
},
},
},
plugins: [
graphql(),
react({
jsxImportSource: mode === 'development' ? '@welldone-software/why-did-you-render' : 'react'
jsxImportSource:
mode === 'development'
? '@welldone-software/why-did-you-render'
: 'react',
}),
// legacy({ target }),
handlebars({
context: {
SNOWPACK_MATOMO: Boolean(SNOWPACK_MATOMO_URL) && Boolean(SNOWPACK_MATOMO_SITE_ID),
SNOWPACK_MATOMO:
Boolean(SNOWPACK_MATOMO_URL) && Boolean(SNOWPACK_MATOMO_SITE_ID),
SNOWPACK_MATOMO_URL,
SNOWPACK_MATOMO_SITE_ID,
}
},
}),
sentryVitePlugin({
org: 'ecrinum-stylo',
project: 'stylo-front',
authToken: env.SENTRY_AUTH_TOKEN
})
authToken: env.SENTRY_AUTH_TOKEN,
}),
],
define: {
APP_VERSION: JSON.stringify(pkg.version),
APP_ENVIRONMENT: JSON.stringify(env.SENTRY_ENVIRONMENT),
SENTRY_DSN: JSON.stringify(env.SENTRY_DSN),
__ANNOTATIONS_CANONICAL_BASE_URL__: JSON.stringify(
env.SNOWPACK_PUBLIC_ANNOTATIONS_CANONICAL_BASE_URL
),
__BACKEND_ENDPOINT__: JSON.stringify(
env.SNOWPACK_PUBLIC_BACKEND_ENDPOINT
),
@@ -74,21 +90,23 @@ export default defineConfig(async ({ mode }) => {
},
resolve: {
alias: {
'react-redux': mode === 'development' ? 'react-redux/lib' : 'react-redux'
}
'react-redux':
mode === 'development' ? 'react-redux/lib' : 'react-redux',
},
},
server: {
port: 3000,
proxy: {
'/graphql': {
target: 'http://127.0.0.1:3030',
prependPath: false
prependPath: false,
},
// as in infrastructure/files/stylo.huma-num.fr.conf
'^/(login/openid|login/local|login/zotero|logout|authorization-code|events)': {
target: 'http://127.0.0.1:3030'
}
}
'^/(login/openid|login/local|login/zotero|logout|authorization-code|events)':
{
target: 'http://127.0.0.1:3030',
},
},
},

test: {
@@ -101,10 +119,10 @@ export default defineConfig(async ({ mode }) => {
'**/*.config.*',
'**/{tests,bin}/*',
'**/*.test.jsx?',
]
],
},
environment: 'jsdom',
setupFiles: ['./tests/setup.js']
}
setupFiles: ['./tests/setup.js'],
},
}
})
Loading

0 comments on commit 8f56961

Please sign in to comment.