allow passing filename query param to get snippet (#1007)

main
Michael Fix 4 years ago committed by GitHub
parent ba2291222a
commit 042a20b60e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -73,9 +73,12 @@ const unsplash = {
},
}
function getSnippet(uid = '', { host } = {}) {
function getSnippet(uid = '', { host, filename } = {}) {
return client
.get(`/snippets/${uid}`, host ? { baseURL: `https://${host}/api` } : undefined)
.get(`/snippets/${uid}`, {
baseURL: host ? `https://${host}/api` : undefined,
params: { filename },
})
.then(res => res.data)
.catch(e => {
console.error(e)

@ -6,13 +6,13 @@ import IndexPage from './index'
import api from '../lib/api'
export async function getServerSideProps({ req, res, query }) {
const path = query.id
const { id: path, filename } = query
const parameter = path.length >= 19 && path.indexOf('.') < 0 ? path : null
let snippet
if (parameter) {
const host = req ? req.headers.host : undefined
snippet = await api.snippet.get(parameter, { host })
snippet = await api.snippet.get(parameter, { host, filename })
if (snippet) {
return { props: { snippet, host } }
}

@ -6,13 +6,14 @@ import EmbedPage from './index'
import api from '../../lib/api'
export async function getServerSideProps({ req, res, query }) {
const path = query.id
const { id: path, filename } = query
const parameter = path.length >= 19 && path.indexOf('.') < 0 ? path : null
let snippet
if (parameter) {
const host = req ? req.headers.host : undefined
snippet = await api.snippet.get(parameter, { host })
snippet = await api.snippet.get(parameter, { host, filename })
if (snippet /* && snippet.gist_id */) {
return { props: { snippet } }
}

Loading…
Cancel
Save