Add opengraph

This commit is contained in:
Chocobozzz 2020-09-02 14:07:22 +02:00
parent 8c5f53c11f
commit fe37b0b26d
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
10 changed files with 97 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

View File

@ -8,7 +8,8 @@
<link rel="icon" type="image/png" href="<%= BASE_URL %>img/favicon.png">
<title>PeerTube Global Search</title>
<title>PeerTube Search</title>
</head>
<body>
<noscript>

View File

@ -30,7 +30,9 @@
</div>
<div class="footer">
<a href="https://framagit.org/framasoft/peertube/search-index/" target="_blank">Source code</a>
<a v-translate href="https://framagit.org/framasoft/peertube/search-index/" target="_blank">Source code</a>
<a v-if="legalNoticesUrl" v-translate :href="legalNoticesUrl" target="_blank">Legal notices</a>
</div>
</footer>
</template>
@ -120,6 +122,7 @@
a {
color: $orange;
font-size: 10px;
margin-right: 10px;
}
}
@ -147,8 +150,19 @@
<script>
import Vue from 'vue'
import { getConfig } from '../shared/config'
export default Vue.extend({
data () {
return {
legalNoticesUrl: ''
}
},
async mounted () {
const config = await getConfig()
this.legalNoticesUrl = config.legalNoticesUrl
}
})
</script>

View File

@ -19,6 +19,8 @@ log:
search-instance:
name: 'PeerTube Search Index'
description: 'Search for your favorite PeerTube videos and channels!'
legal_notices_url: ''
instances-index:
# Contains PeerTube instance hosts the indexer will index

View File

@ -30,6 +30,7 @@
"cors": "^2.8.5",
"express": "^4.16.4",
"express-validator": "^6.1.1",
"fs-extra": "^9.0.1",
"js-yaml": "^3.12.1",
"lodash": "^4.17.15",
"mkdirp": "^1.0.4",
@ -51,6 +52,7 @@
"@types/config": "^0.0.36",
"@types/express": "^4.16.1",
"@types/fluent-ffmpeg": "^2.1.14",
"@types/fs-extra": "^9.0.1",
"@types/lodash": "^4.14.149",
"@types/mkdirp": "^1.0.0",
"@types/morgan": "^1.7.32",

View File

@ -15,6 +15,8 @@ import { VideosIndexer } from './server/lib/schedulers/videos-indexer'
import { initVideosIndex } from './server/lib/elastic-search-videos'
import { initChannelsIndex } from './server/lib/elastic-search-channels'
import { join } from 'path'
import { send } from 'process'
import { readFile } from 'fs-extra'
const app = express()
@ -40,8 +42,37 @@ app.use('/js/', express.static(join(__dirname, '../client/dist/js')))
app.use('/css/', express.static(join(__dirname, '../client/dist/css')))
app.use('/img/', express.static(join(__dirname, '../client/dist/img')))
app.use('/*', function (req, res) {
return res.sendFile(join(__dirname, '../client/dist/index.html'))
let indexHTML: string
app.use('/*', async function (req, res) {
res.set('Content-Type', 'text/html; charset=UTF-8')
if (indexHTML) return res.send(indexHTML)
const buffer = await readFile(join(__dirname, '../client/dist/index.html'))
const url = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
const title = CONFIG.SEARCH_INSTANCE.NAME
const description = CONFIG.SEARCH_INSTANCE.DESCRIPTION
const tags = `
<meta property="og:url" content="${url}">
<meta property="og:title" content="${title}">
<meta property="og:description" content="${description}">
<meta property="og:image" content="${url}/img/card-opengraph.jpg">
<meta property="og:site_name" content="${title}">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@joinpeertube">
<meta name="twitter:creator" content="@chocobozzz">
<meta name="twitter:title" content="${title}">
<meta name="twitter:description" content="${description}">
<meta name="twitter:image" content="${url}/img/card-opengraph.jpg">`
indexHTML = buffer.toString()
indexHTML = indexHTML.replace('</head>', tags + '</head>')
return res.send(indexHTML)
})
// ----------- Errors -----------

View File

@ -18,6 +18,7 @@ export { configRouter }
async function getConfig (req: express.Request, res: express.Response) {
return res.json({
searchInstanceName: CONFIG.SEARCH_INSTANCE.NAME,
legalNoticesUrl: CONFIG.SEARCH_INSTANCE.LEGAL_NOTICES_URL,
indexedHostsCount: VideosIndexer.Instance.getIndexedHosts().length,
indexedInstancesUrl: CONFIG.INSTANCES_INDEX.PUBLIC_URL
} as ServerConfig)

View File

@ -24,7 +24,9 @@ const CONFIG = {
LEVEL: config.get<string>('log.level')
},
SEARCH_INSTANCE: {
NAME: config.get<string>('search-instance.name')
NAME: config.get<string>('search-instance.name'),
DESCRIPTION: config.get<string>('search-instance.description'),
LEGAL_NOTICES_URL: config.get<string>('search-instance.legal_notices_url')
},
INSTANCES_INDEX: {
URL: config.get<string>('instances-index.url'),

View File

@ -4,4 +4,6 @@ export interface ServerConfig {
indexedHostsCount: number
indexedInstancesUrl: string
legalNoticesUrl: string
}

View File

@ -117,6 +117,13 @@
dependencies:
"@types/node" "*"
"@types/fs-extra@^9.0.1":
version "9.0.1"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.1.tgz#91c8fc4c51f6d5dbe44c2ca9ab09310bd00c7918"
integrity sha512-B42Sxuaz09MhC3DDeW5kubRcQ5by4iuVQ0cRRWM2lggLzAa/KVom0Aft/208NgMvNQQZ86s5rVcqDdn/SH0/mg==
dependencies:
"@types/node" "*"
"@types/json-schema@^7.0.3":
version "7.0.4"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"
@ -409,6 +416,11 @@ asynckit@^0.4.0:
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=
at-least-node@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
atomic-sleep@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/atomic-sleep/-/atomic-sleep-1.0.0.tgz#eb85b77a601fc932cfe432c5acd364a9e2c9075b"
@ -1199,6 +1211,16 @@ fresh@0.5.2:
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=
fs-extra@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc"
integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==
dependencies:
at-least-node "^1.0.0"
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^1.0.0"
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@ -1259,7 +1281,7 @@ globals@^12.1.0:
dependencies:
type-fest "^0.8.1"
graceful-fs@^4.1.2:
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.4"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
@ -1553,6 +1575,15 @@ json5@^2.1.1:
dependencies:
minimist "^1.2.5"
jsonfile@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179"
integrity sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==
dependencies:
universalify "^1.0.0"
optionalDependencies:
graceful-fs "^4.1.6"
jsprim@^1.2.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
@ -2679,6 +2710,11 @@ typescript@^3.7.5:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.3.tgz#d3ac8883a97c26139e42df5e93eeece33d610b8a"
integrity sha512-D/wqnB2xzNFIcoBG9FG8cXRDjiqSTbG2wd8DMZeQyJlP1vfTkIxH4GKveWaEBYySKIg+USu+E+EDIR47SqnaMQ==
universalify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==
unpipe@1.0.0, unpipe@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"