Skip to content

Commit

Permalink
feat: add basis for new theme architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
shezard committed Feb 10, 2024
1 parent 9d8e70c commit 66c0a32
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 9 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,11 @@ Setup an .env file with
Then run

```bash
just get_data <theme>
```

### Uniquify data in src/lib/data.json

```bash
node unique.mjs > src/lib/data.json
just build <theme>
```

### TODO

[ ] Path shouldn't be hard coded
[ ] Drawing them should be handled in theme.json file
[ ] Drawing them should be handled in data/<theme>.json file
[ ] UI should support themes
157 changes: 157 additions & 0 deletions data/castle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
[
{
"alt": "white and gray castle on top of hill",
"url": "https://images.unsplash.com/photo-1595187886119-2da48485ce39?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "akloska"
},
{
"alt": "brown and white concrete building under blue sky during daytime",
"url": "https://images.unsplash.com/photo-1609515744087-ba13b7fbafc1?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "jben9211"
},
{
"alt": "brown brick building under blue sky during daytime",
"url": "https://images.unsplash.com/photo-1596643421231-233772072436?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "markusspiske"
},
{
"alt": "brown fort with flag on top[ during daytime",
"url": "https://images.unsplash.com/photo-1558280516-e7a3b201cb7a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "lucas_carl"
},
{
"alt": "grayscale photo of castle surrounded by trees",
"url": "https://images.unsplash.com/photo-1610287719165-ee7a16c241fd?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "pietyo"
},
{
"alt": "brown concrete castle surround by trees",
"url": "https://images.unsplash.com/photo-1548781695-12c50fd2ca76?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "julie_soul"
},
{
"alt": "white concrete building surrounded by green trees under white clouds during daytime",
"url": "https://images.unsplash.com/photo-1621699097131-ba95d99bb5a0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "daniels_photofactory"
},
{
"alt": "Disney Castle, Singapore",
"url": "https://images.unsplash.com/photo-1509407336566-fca158fddcce?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "jorgem9"
},
{
"alt": "brown concrete castle",
"url": "https://images.unsplash.com/photo-1551727032-7642eb0a843e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "maud_boc"
},
{
"alt": "castle on hill",
"url": "https://images.unsplash.com/photo-1557217713-d9fd1a8370d2?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "mrmarkdejong"
},
{
"alt": "brown concrete building near body of water during daytime",
"url": "https://images.unsplash.com/photo-1604583886011-85dfa9dd03cf?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "bryanmillarwalker"
},
{
"alt": "white and blue castle on top of mountain",
"url": "https://images.unsplash.com/photo-1619779762728-0edbfa321936?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "nikolasvako"
},
{
"alt": "gray and black concrete castle surrounded by green trees under blue sky during daytime",
"url": "https://images.unsplash.com/photo-1613927676191-8ef796b5916d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "dmaximo89"
},
{
"alt": "brown concrete building with birds flying during daytime",
"url": "https://images.unsplash.com/photo-1581878611389-78121d751dd9?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "honni"
},
{
"alt": "Disney World Cinderella Castle",
"url": "https://images.unsplash.com/photo-1578230706129-5e3ebca647d3?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "imajingation"
},
{
"alt": "brown concrete building near body of water during daytime",
"url": "https://images.unsplash.com/photo-1593507905413-e3f6716bf887?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "gontranid"
},
{
"alt": "gray concrete building under cloudy sky during daytime",
"url": "https://images.unsplash.com/photo-1630397794941-46ed66b8fbca?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "supergios"
},
{
"alt": "concrete castle during day",
"url": "https://images.unsplash.com/photo-1560682326-60bb01e84447?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "alexsilitra"
},
{
"alt": "brown and green grass field near body of water under white clouds during daytime",
"url": "https://images.unsplash.com/photo-1594735514802-53366fc3c84e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "celinecp"
},
{
"alt": "Neuschwanstein Castle, Germany",
"url": "https://images.unsplash.com/photo-1534313314376-a72289b6181e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "martye"
},
{
"alt": "brown brick building under white sky during daytime",
"url": "https://images.unsplash.com/photo-1612021091953-ff31644a1489?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "vmelnyk"
},
{
"alt": "aerial photography of gray tower",
"url": "https://images.unsplash.com/photo-1563723394315-4847184f2cde?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "arlynsupnet"
},
{
"alt": "gray concrete castle on cliff during daytime",
"url": "https://images.unsplash.com/photo-1571321619786-a50665c0fc5b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "carlee52"
},
{
"alt": "brown castle on body of water",
"url": "https://images.unsplash.com/photo-1515515332716-78b07ef2afc0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "cant92"
},
{
"alt": "shallow focus photo of gray castle",
"url": "https://images.unsplash.com/photo-1577493327436-6b54af0aabb3?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "seansinspired"
},
{
"alt": "person holding torch in building interior",
"url": "https://images.unsplash.com/photo-1519074069444-1ba4fff66d16?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "linussandvide"
},
{
"alt": "grey castle on rock mountain",
"url": "https://images.unsplash.com/photo-1561846005-6855aac17b10?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "gonz_ddl"
},
{
"alt": "concrete bridge beside tree",
"url": "https://images.unsplash.com/photo-1578411769077-5bcbd218cdd7?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "luizagiannelli"
},
{
"alt": "people walking on snow covered field near brown concrete building during daytime",
"url": "https://images.unsplash.com/photo-1599661046289-e31897846e41?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "meric"
},
{
"alt": "brown and gray concrete castle under cloudy sky during daytime",
"url": "https://images.unsplash.com/photo-1580989702236-3d389d0f2a59?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODQxMjd8&ixlib=rb-4.0.3&q=80&w=400",
"author": "jmeguilos"
},
{
"alt": "brown and gray houses",
"url": "https://images.unsplash.com/photo-1575065413697-c30c41266187?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODEyMTF8&ixlib=rb-4.0.3&q=80&w=400",
"author": "cajeo"
}
]
36 changes: 35 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,38 @@ 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}]' > data.json
jq '[.[] | {alt: .alt_description, url: .urls.small, author: .user.username}]'

get_test theme:
#!/bin/bash
echo -e '[{\n
"alt": "brown and gray houses",\n
"url": "https://images.unsplash.com/photo-1575065413697-c30c41266187?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0NTIwNzl8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MDc1ODEyMTF8&ixlib=rb-4.0.3&q=80&w=400",\n
"author": "cajeo"\n
}]'

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 './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:
#!/bin/bash
just make_unique {{theme}} > ./data/{{theme}}-tmp.json && mv ./data/{{theme}}-tmp.json ./data/{{theme}}.json

0 comments on commit 66c0a32

Please sign in to comment.