mirror of
https://github.com/cupcakearmy/nicco.io.git
synced 2025-12-11 08:25:00 +00:00
test new features
This commit is contained in:
25
src/lib/wp.js
Normal file
25
src/lib/wp.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const isDev = process.env.NODE_ENV !== 'production'
|
||||
axios.defaults.baseURL = `${isDev ? 'http://localhost' : 'https://api.nicco.io'}/wp-json/wp/v2`
|
||||
|
||||
function normalize(post) {
|
||||
return {
|
||||
...post.acf,
|
||||
id: post.id,
|
||||
title: post.title.rendered,
|
||||
content: post.content.rendered,
|
||||
}
|
||||
}
|
||||
|
||||
export async function getOne(url, params = {}) {
|
||||
const p = new URLSearchParams(params).toString()
|
||||
const { data } = await axios(`${url}?${p}`)
|
||||
if (!data.length) return null
|
||||
else return normalize(data[0])
|
||||
}
|
||||
|
||||
export async function getAll(url, params = {}) {
|
||||
const { data } = await axios(url)
|
||||
return data.map(normalize)
|
||||
}
|
||||
Reference in New Issue
Block a user