mirror of
https://github.com/cupcakearmy/nicco.io.git
synced 2024-12-21 23:56:26 +00:00
cache data
This commit is contained in:
parent
0306a0cbbf
commit
b3446c6048
@ -1,9 +1,8 @@
|
||||
{
|
||||
"scripts": {
|
||||
"dev": "sapper dev",
|
||||
"build": "sapper build",
|
||||
"export": "sapper export",
|
||||
"start": "node __sapper__/build"
|
||||
"start": "serve __sapper__/export"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.20.0",
|
||||
|
@ -49,3 +49,8 @@ export function sortByAndMapDate(data, format = 'MMM YY') {
|
||||
date: dj(work.date * 1000).format(format),
|
||||
}))
|
||||
}
|
||||
|
||||
export function respond(res, body) {
|
||||
res.setHeader('Content-Type', 'application/json')
|
||||
res.end(JSON.stringify(body))
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
<script context="module">
|
||||
import { getOne } from '../lib/wp'
|
||||
|
||||
export async function preload() {
|
||||
const data = await getOne('pages', { slug: 'about' })
|
||||
return { data }
|
||||
return this.fetch('/api/pages/about.json').then((res) => res.json())
|
||||
}
|
||||
</script>
|
||||
|
||||
|
13
src/routes/api/[...slug].json.js
Normal file
13
src/routes/api/[...slug].json.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { respond, getAll, getOne, sortByAndMapDate } from '../../lib/wp'
|
||||
|
||||
export async function get(req, res) {
|
||||
const [type, slug] = req.params.slug
|
||||
|
||||
if (slug) {
|
||||
const data = await getOne(type, { slug })
|
||||
respond(res, { data })
|
||||
} else {
|
||||
const data = await getAll(type)
|
||||
respond(res, { data: sortByAndMapDate(data) })
|
||||
}
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
<script context="module">
|
||||
import { getOne } from '../../lib/wp'
|
||||
export async function preload({ params }) {
|
||||
const { slug } = params
|
||||
const post = await getOne('posts', { slug })
|
||||
return { post }
|
||||
return this.fetch(`/api/posts/${params.slug}.json`).then((res) => res.json())
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -12,10 +9,10 @@
|
||||
import WPAdapter from '../../components/WPAdapter.svelte'
|
||||
import PostAttributes from '../../components/PostAttributes.svelte'
|
||||
|
||||
export let post
|
||||
export let data
|
||||
</script>
|
||||
|
||||
<SimplePage title={post.title} expanded={false} readable>
|
||||
<PostAttributes {post} full />
|
||||
<WPAdapter content={post.content} />
|
||||
<SimplePage title={data.title} expanded={false} readable>
|
||||
<PostAttributes post={data} full />
|
||||
<WPAdapter content={data.content} />
|
||||
</SimplePage>
|
||||
|
@ -1,9 +1,6 @@
|
||||
<script context="module">
|
||||
import { getAll } from '../../lib/wp'
|
||||
|
||||
export async function preload() {
|
||||
const data = await getAll('posts')
|
||||
return { data }
|
||||
return this.fetch('/api/posts.json').then((res) => res.json())
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
<script context="module">
|
||||
import { getOne } from '../lib/wp'
|
||||
|
||||
export async function preload() {
|
||||
const data = await getOne('pages', { slug: 'privacy' })
|
||||
return { data }
|
||||
return this.fetch('/api/pages/privacy.json').then((res) => res.json())
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
export async function get(req, res, next) {
|
||||
const data = [
|
||||
{
|
||||
name: 'Unbrew',
|
||||
link: 'https://github.com/cupcakearmy/unbrew',
|
||||
title: 'Manage unused dependecies for brew',
|
||||
date: '2020',
|
||||
body:
|
||||
'Well... anyone that has been using brew in macOS for some time will have encountered the issue of doing a simple brew list and discovering loads of packages they have never heard of. Often this is the result of installing some packages that bring dependecies, but since brew does not uninstall them when you delete the package they came with, they will hang around for ever basically.',
|
||||
},
|
||||
{
|
||||
name: 'Autorestic',
|
||||
link: 'https://cupcakearmy.github.io/autorestic/',
|
||||
title: 'High level backup level CLI utility for restic.',
|
||||
date: '2019',
|
||||
body:
|
||||
'Autorestic is a wrapper around the amazing restic. While being amazing the restic cli can be a bit overwhelming and difficoult to manage if you have many different location that you want to backup to multiple locations. This utility is aimed at making this easier.',
|
||||
},
|
||||
]
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json',
|
||||
})
|
||||
res.end(JSON.stringify(data))
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
<script context="module">
|
||||
import { getAll, sortByAndMapDate } from '../lib/wp'
|
||||
|
||||
export async function preload() {
|
||||
const data = await getAll('projects')
|
||||
return { data: sortByAndMapDate(data) }
|
||||
return this.fetch('/api/projects.json').then((res) => res.json())
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
<script context="module">
|
||||
import { getAll, sortByAndMapDate } from '../lib/wp'
|
||||
|
||||
export async function preload() {
|
||||
const data = await getAll('works')
|
||||
return { data: sortByAndMapDate(data) }
|
||||
return this.fetch('/api/works.json').then((res) => res.json())
|
||||
}
|
||||
</script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user