Skip to content

Commit acc9c45

Browse files
author
Glitch (glitch-in-bio)
committed
✌️😄 Checkpoint
./vite-plugin-glitch-handlebars/context.ts:31317407/742 ./vite-plugin-glitch-handlebars/index.ts:31317407/2937 ./vite-plugin-glitch-handlebars/partials.ts:31317407/1756 ./package.json:31317407/1085 ./vite.config.js:31317407/1580 ./watch.json:31317407/513 ./README.md:31317407/503
1 parent 12383cb commit acc9c45

File tree

8 files changed

+271
-186
lines changed

8 files changed

+271
-186
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ To get started, open `settings.json` and add your name, avatar, social accounts,
1212
To help you make the site your own we've included some themes. In `settings.json` you can enter `glitch`, `gallery`, or `menu` as the value for `theme`. Use any theme you want, add a new one, or start with one and edit it to make it your own. _If you don't have a valid theme entered, the site will default to the styles outlined in `style.css`._
1313

1414
* The images you add in `settings.json` as the `img` property for each link will display if you use the `gallery` or `menu` themes. Upload yours in `assets` and copy the link from there if they aren't already online.
15+
* If you notice your preview is a little out of sync with your `settings.json`, hit the reload button in the preview window and it should update!
1516

1617
__To get started changing the appearance of your site, or adding your own theme, use `custom-theme.css` to set global variables like colors and fonts, and add any rules you like. Make sure you enter your theme by name in `settings.json` as the `theme` property (you can also change the filename if you like, just remember to update it in your settings JSON.__
1718

@@ -36,6 +37,8 @@ ___The images in the default settings.json file are from a remix of [Generative
3637

3738
`assets`: Add images here and copy the links into `settings.json` to show them in your site.
3839

40+
`vite-plugin-glitch-handlebars/`: This folder contains a modified version of [vite-plugin-handlebars](https://github.com/alexlafroscia/vite-plugin-handlebars) we use to improve the preview experience while you work on your app–you shouldn't need to change anything in here!
41+
3942
![Glitch](https://cdn.glitch.com/a9975ea6-8949-4bab-addb-8a95021dc2da%2FLogo_Color.svg?v=1602781328576)
4043

4144
## You built this with Glitch!

package-lock.json

Lines changed: 39 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"name": "glitch-in-bio",
33
"version": "0.0.1",
44
"description": "Your very own link-in-bio app.",
5-
"main": "server.js",
5+
"main": "index.html",
66
"scripts": {
77
"start": "vite",
88
"build": "vite build",
99
"serve": "vite preview"
1010
},
1111
"devDependencies": {
12-
"vite-plugin-handlebars": "^1.6.0",
12+
"handlebars": "^4.7.6",
1313
"vite": "^2.5.0"
1414
},
1515
"browserslist": [
@@ -24,5 +24,6 @@
2424
},
2525
"glitch": {
2626
"projectType": "generated_static"
27-
}
27+
},
28+
"dependencies": {}
2829
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export type Context =
2+
| Record<string, unknown>
3+
| ((path: string) => Record<string, unknown>)
4+
| ((path: string) => Promise<Record<string, unknown>>);
5+
6+
export async function resolveContext(
7+
context: Context | undefined,
8+
pagePath: string
9+
): Promise<Record<string, unknown> | undefined> {
10+
if (typeof context === 'undefined') {
11+
return context;
12+
}
13+
14+
if (typeof context === 'function') {
15+
return resolveContext(await context(pagePath), pagePath);
16+
}
17+
18+
const output: Record<string, unknown> = {};
19+
20+
for (const key of Object.keys(context)) {
21+
const value = context[key];
22+
23+
if (typeof value === 'function') {
24+
output[key] = await value(pagePath);
25+
} else {
26+
output[key] = value;
27+
}
28+
}
29+
30+
return output;
31+
}

0 commit comments

Comments
 (0)