-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustfile
37 lines (28 loc) · 1.32 KB
/
justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
set dotenv-load := true
init theme:
#!/bin/bash
test -f ./src/data/{{theme}}.json || echo '[]' > ./src/data/{{theme}}.json
get_data theme:
#!/bin/bash
curl "https://api.unsplash.com/photos/random?count=100&orientation=portrait&query={{theme}}" \
--header "Authorization: Client-ID $ACCESS_KEY" | \
jq '[.[] | {alt: .alt_description, url: .urls.small, author: .user.username}]'
make_unique theme:
#!/usr/bin/env bash
":" //# comment; exec /usr/bin/env node --no-warnings --input-type=module - "$@" < "$0"
import { readFileSync } from 'node:fs';
import { promisify } from 'node:util';
import { exec } from 'node:child_process';
import existingData from './src/data/{{theme}}.json' assert { type: 'json' };
const pexec = promisify(exec);
const {stdout: newData } = await pexec('just get_data {{theme}}');
const data = JSON.parse(newData).concat(existingData);
const indexedData = data.reduce((indexedData, item) => {
const key = new URL(item.url);
indexedData[key.pathname] = item;
return indexedData;
}, {});
console.log(JSON.stringify(Object.values(indexedData), null, 4));
build theme: (init theme)
#!/bin/bash
just make_unique {{theme}} > ./src/data/{{theme}}-tmp.json && mv ./src/data/{{theme}}-tmp.json ./src/data/{{theme}}.json