date stuff

This commit is contained in:
cupcakearmy 2020-09-28 16:02:16 +02:00
parent e4ef072769
commit 4c58bfc4cc
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
5 changed files with 11 additions and 12 deletions

View File

@ -9,6 +9,8 @@
return dj(date).format('MMM D, YYYY')
}
$: console.log(post)
$: created = format(post.date)
$: modified = format(post.modified)
</script>

View File

@ -1,4 +1,6 @@
<script>
import dj from 'dayjs'
export let project
</script>
@ -37,7 +39,7 @@
<a href={project.link} target="_blank" rel="noopener">
<h2>{project.title}</h2>
</a>
<div><b>{project.description}</b> <b class="date">{project.date}</b></div>
<div><b>{project.description}</b> <b class="date">{dj(project.date * 1000).format('MMM YY')}</b></div>
<p>
{@html project.content}

View File

@ -1,4 +1,5 @@
<script>
import dj from 'dayjs'
import ImageFrame from '../components/ImageFrame.svelte'
export let work
@ -49,7 +50,7 @@
</a>
<div class="horizontal regular">
<div>{work.role}</div>
<div>{work.date}</div>
<div>{dj(work.date * 1000).format('MMM YY')}</div>
</div>
<p>
{@html work.content}

View File

@ -1,5 +1,4 @@
import axios from 'axios'
import dj from 'dayjs'
const isDev = process.env.NODE_ENV !== 'production' && false
axios.defaults.baseURL = `${isDev ? 'http://localhost' : 'https://api.nicco.io'}/wp-json/wp/v2`
@ -41,13 +40,8 @@ export async function getAll(url, params = {}) {
return results.map(normalize)
}
export function sortByAndMapDate(data, format = 'MMM YY') {
return data
.sort((a, b) => parseInt(b.date) - parseInt(a.date))
.map((work) => ({
...work,
date: dj(work.date * 1000).format(format),
}))
export function sortByDate(data) {
return data.sort((a, b) => parseInt(b.date) - parseInt(a.date))
}
export function respond(res, body) {

View File

@ -1,4 +1,4 @@
import { respond, getAll, getOne, sortByAndMapDate } from '../../lib/wp'
import { respond, getAll, getOne, sortByDate } from '../../lib/wp'
export async function get(req, res) {
const [type, slug] = req.params.slug
@ -8,6 +8,6 @@ export async function get(req, res) {
respond(res, { data })
} else {
const data = await getAll(type)
respond(res, { data: sortByAndMapDate(data) })
respond(res, { data: sortByDate(data) })
}
}