Fix URL bugs

main
Mike Fix 7 years ago
parent bdc9211d25
commit 8dec652c2a

@ -26,8 +26,7 @@ async function tweet(encodedImage) {
.catch(checkIfRateLimited) .catch(checkIfRateLimited)
} }
const getGist = id => { const getGist = uid => {
const uid = id.split('/').pop()
return gistClient return gistClient
.get(`/gists/${uid}`) .get(`/gists/${uid}`)
.then(res => res.data) .then(res => res.data)

@ -31,17 +31,17 @@ import { getState, saveState } from '../lib/util'
const removeQueryString = str => { const removeQueryString = str => {
const qI = str.indexOf('?') const qI = str.indexOf('?')
return str.slice(1, qI) return qI > 0 ? str.substr(0, qI) : str
} }
class Editor extends React.Component { class Editor extends React.Component {
static async getInitialProps({ asPath, query }) { static async getInitialProps({ asPath, query }) {
const path = removeQueryString(asPath) const path = removeQueryString(asPath.split('/').pop())
const queryParams = getQueryStringState(query) const queryParams = getQueryStringState(query)
const initialState = Object.keys(queryParams).length ? queryParams : null const initialState = Object.keys(queryParams).length ? queryParams : null
try { try {
// TODO fix this hack // TODO fix this hack
if (path.length >= 20 && path.indexOf('.') === -1) { if (path.length >= 19 && path.indexOf('.') === -1) {
const content = await api.getGist(path) const content = await api.getGist(path)
return { content, initialState } return { content, initialState }
} }

Loading…
Cancel
Save