diff --git a/lib/api.js b/lib/api.js index ec2d845..bcc3602 100644 --- a/lib/api.js +++ b/lib/api.js @@ -26,8 +26,7 @@ async function tweet(encodedImage) { .catch(checkIfRateLimited) } -const getGist = id => { - const uid = id.split('/').pop() +const getGist = uid => { return gistClient .get(`/gists/${uid}`) .then(res => res.data) diff --git a/pages/editor.js b/pages/editor.js index 8994b24..3370aff 100644 --- a/pages/editor.js +++ b/pages/editor.js @@ -31,17 +31,17 @@ import { getState, saveState } from '../lib/util' const removeQueryString = str => { const qI = str.indexOf('?') - return str.slice(1, qI) + return qI > 0 ? str.substr(0, qI) : str } class Editor extends React.Component { static async getInitialProps({ asPath, query }) { - const path = removeQueryString(asPath) + const path = removeQueryString(asPath.split('/').pop()) const queryParams = getQueryStringState(query) const initialState = Object.keys(queryParams).length ? queryParams : null try { // TODO fix this hack - if (path.length >= 20 && path.indexOf('.') === -1) { + if (path.length >= 19 && path.indexOf('.') === -1) { const content = await api.getGist(path) return { content, initialState } }