Skip to content

Commit

Permalink
feat(export): ajoute le rel=canonical lors de la preview
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot committed Jan 22, 2025
1 parent 52fe337 commit 8e2974f
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 43 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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-dev.huma-num.fr
SENTRY_DSN: https://276d5080680a70a3edf98783a2b264d0@o4507130700496896.ingest.de.sentry.io/4507130704560208
SENTRY_ENVIRONMENT: dev

Expand Down
1 change: 1 addition & 0 deletions front/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
APP_VERSION: true,
APP_ENVIRONMENT: true,
SENTRY_DSN: true,
__ANNOTATIONS_CANONICAL_BASE_URL__: true,
__BACKEND_ENDPOINT__: true,
__GRAPHQL_ENDPOINT__: true,
__PANDOC_EXPORT_ENDPOINT__: true,
Expand Down
8 changes: 8 additions & 0 deletions front/src/components/Preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 }} />
</>
)
Expand Down
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__,
pandocExportEndpoint: __PANDOC_EXPORT_ENDPOINT__,
pandocExportHost:
Expand Down
3 changes: 3 additions & 0 deletions front/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export default defineConfig(async ({ mode }) => {
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
),
Expand Down
81 changes: 42 additions & 39 deletions graphql/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ convict.addFormat(require('convict-format-with-validator').url)
convict.addFormat({
name: 'mongodb-url',
coerce: (v) => v.toString(),
validate: (val) => assert.ok(isURL(val, { require_tld: false, protocols: ['mongodb', 'mongodb+srv'] }), 'must be a mongodb protocol URL')

validate: (val) =>
assert.ok(
isURL(val, { require_tld: false, protocols: ['mongodb', 'mongodb+srv'] }),
'must be a mongodb protocol URL'
),
})
/**
* @type {convict.Config<{
Expand All @@ -20,151 +23,151 @@ module.exports = convict({
export: {
baseUrl: {
format: String,
env: 'EXPORT_CANONICAL_BASE_URL',
default: 'http://127.0.0.1:3060'
env: 'SNOWPACK_PUBLIC_ANNOTATIONS_CANONICAL_BASE_URL',
default: 'http://127.0.0.1:3060',
},
urlEndpoint: {
format: 'url',
env: 'SNOWPACK_PUBLIC_PANDOC_EXPORT_ENDPOINT',
default: 'http://127.0.0.1:3080'
}
default: 'http://127.0.0.1:3080',
},
},
mongo: {
databaseUrl: {
default: 'mongodb://127.0.0.1:27017/stylo-dev',
format: 'mongodb-url',
env: 'DATABASE_URL'
}
env: 'DATABASE_URL',
},
},
oauthProvider: {
name: {
format: String,
env: 'OPENID_CONNECT_NAME',
default: null
default: null,
},
issuer: {
format: 'url',
env: 'OPENID_CONNECT_ISSUER',
default: null
default: null,
},
callbackUrl: {
format: 'url',
env: 'OPENID_CONNECT_CALLBACK_URL',
default: 'http://localhost:3000/authorization-code/callback'
default: 'http://localhost:3000/authorization-code/callback',
},
client: {
id: {
format: String,
sensitive: true,
env: 'OPENID_CONNECT_CLIENT_ID',
default: null
default: null,
},
secret: {
format: String,
sensitive: true,
env: 'OPENID_CONNECT_CLIENT_SECRET',
default: null
}
default: null,
},
},
scope: {
default: 'profile email',
env: 'OPENID_CONNECT_SCOPE'
env: 'OPENID_CONNECT_SCOPE',
},
auth: {
tokenUrl: {
format: 'url',
env: 'OPENID_CONNECT_TOKEN_URL',
default: null
default: null,
},
userInfo: {
format: 'url',
env: 'OPENID_CONNECT_USER_INFO_URL',
default: null
default: null,
},
url: {
format: 'url',
env: 'OPENID_CONNECT_AUTH_URL',
default: null
}
}
default: null,
},
},
},
port: {
format: 'port',
env: 'PORT',
default: 3030
default: 3030,
},
securedCookie: {
format: Boolean,
env: 'HTTPS',
default: false
default: false,
},
security: {
cors: {
origin: {
// url1 url2
default: 'http://127.0.0.1:3000 http://127.0.0.1:3030',
env: 'ALLOW_CORS_FRONTEND'
}
env: 'ALLOW_CORS_FRONTEND',
},
},
jwt: {
secret: {
format: String,
sensitive: true,
env: 'JWT_SECRET_SESSION_COOKIE',
default: null
}
default: null,
},
},
session: {
secret: {
format: String,
sensitive: true,
env: 'SESSION_SECRET',
default: null
}
}
default: null,
},
},
},
zotero: {
accessPoint: {
format: 'url',
env: 'ZOTERO_ACCESS_TOKEN_ENDPOINT',
default: 'https://www.zotero.org/oauth/access'
default: 'https://www.zotero.org/oauth/access',
},
authorize: {
format: 'url',
env: 'ZOTERO_AUTHORIZE_ENDPOINT',
default: 'https://www.zotero.org/oauth/authorize'
default: 'https://www.zotero.org/oauth/authorize',
},
requestToken: {
format: 'url',
env: 'ZOTERO_REQUEST_TOKEN_ENDPOINT',
default: 'https://www.zotero.org/oauth/request'
default: 'https://www.zotero.org/oauth/request',
},
auth: {
callbackUrl: {
format: 'url',
env: 'ZOTERO_AUTH_CALLBACK_URL',
default: 'http://localhost:3030/authorization-code/zotero/callback'
default: 'http://localhost:3030/authorization-code/zotero/callback',
},
clientKey: {
format: String,
sensitive: true,
env: 'ZOTERO_AUTH_CLIENT_KEY',
default: null
default: null,
},
clientSecret: {
format: String,
sensitive: true,
env: 'ZOTERO_AUTH_CLIENT_SECRET',
default: null
}
default: null,
},
},
},
sentry: {
dsn: {
format: 'url',
env: 'SENTRY_GRAPHQL_DSN',
default: null,
nullable: true
}
}
nullable: true,
},
},
})
4 changes: 2 additions & 2 deletions infrastructure/inventories/prod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ graphql_endpoint={{ lookup('env', 'SNOWPACK_PUBLIC_GRAPHQL_ENDPOINT') or 'https:
# Conserve stylo.ecrituresnumeriques.ca car les annotations hypothes.is sont liées à ce nom de domaine
pandoc_export_endpoint={{ lookup('env', 'SNOWPACK_PUBLIC_PANDOC_EXPORT_ENDPOINT') or 'https://export.stylo.huma-num.fr' }}
human_id_register_endpoint={{ lookup('env', 'SNOWPACK_PUBLIC_HUMAN_ID_REGISTER_ENDPOINT') or 'https://humanid.huma-num.fr/register?service=https://stylo.huma-num.fr/authorization-code/callback' }}
# Désactive l'URL canonical vers stylo.huma-num.fr car Hypthesis ne sait pas faire le lien
export_canonical_base_url=''
#
export_canonical_base_url='https://stylo.ecrituresnumeriques.ca'
export_allowed_instance_base_urls='https://stylo.huma-num.fr'
zotero_auth_callback_url='http://stylo.huma-num.fr/authorization-code/zotero/callback'
# Configuration des analytics
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/templates/.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SNOWPACK_PUBLIC_PANDOC_EXPORT_ENDPOINT={{pandoc_export_endpoint}}
SNOWPACK_PUBLIC_HUMAN_ID_REGISTER_ENDPOINT={{human_id_register_endpoint}}
SNOWPACK_MATOMO_URL={{matomo_url}}
SNOWPACK_MATOMO_SITE_ID={{matomo_site_id}}
EXPORT_CANONICAL_BASE_URL={{export_canonical_base_url}}
SNOWPACK_PUBLIC_ANNOTATIONS_CANONICAL_BASE_URL={{export_canonical_base_url}}
ZOTERO_AUTH_CLIENT_KEY={{zotero_auth_client_key}}
ZOTERO_AUTH_CLIENT_SECRET={{zotero_auth_client_secret}}
ZOTERO_AUTH_CALLBACK_URL={{zotero_auth_callback_url}}
Expand Down
2 changes: 1 addition & 1 deletion stylo-example.env
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ SNOWPACK_PUBLIC_PANDOC_EXPORT_ENDPOINT=http://127.0.0.1:3080
SNOWPACK_PUBLIC_HUMAN_ID_REGISTER_ENDPOINT=https://humanid.huma-num.fr/register?service=http://localhost:3030/authorization-code/callback
SNOWPACK_MATOMO_URL=https://example.matomo.cloud/
SNOWPACK_MATOMO_SITE_ID=0
EXPORT_CANONICAL_BASE_URL=http://localhost:3060
SNOWPACK_PUBLIC_ANNOTATIONS_CANONICAL_BASE_URL=http://localhost:3060
SE_GRAPHQL_TOKEN=

0 comments on commit 8e2974f

Please sign in to comment.