diff --git a/lib/api.js b/lib/api.js index 0dddb00..2072971 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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) diff --git a/pages/[id].js b/pages/[id].js index f238d9a..9c504dd 100644 --- a/pages/[id].js +++ b/pages/[id].js @@ -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 } } } diff --git a/pages/embed/[id].js b/pages/embed/[id].js index a4dec7e..cf173a0 100644 --- a/pages/embed/[id].js +++ b/pages/embed/[id].js @@ -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 } } }