Website: temperature-blanket.com
Visualize your city's historical climate data, create color gauges, and preview your pattern for your crochet or knitting temperature project. Save your project in your browser and as a URL, and download project information in PDF, CSV, and PNG files.
Built with:
To run this site locally on your computer for development, clone this repository and create a .env file. Additionally, in order for certain features to work you'll need to register for some free API services.
๐ก Node.js must be installed on your machine.
-
Copy the .env.example file to a new file named
.envin the root directory of your project. -
For the location search features to work, register for a free GeoNames username. You will then receive an email with a confirmation link and after you have confirmed the email you can enable your account for the webservice on your account page. In your
.envfile, setSECRET_GEONAMES_USERNAMEto your GeoNames username. The free plan gets 10,000 credits per month. -
For the Meteostat weather data features to work, sign up for the free Meteostat Base plan through RapidAPI. In your
.envfile, setSECRET_METEOSTAT_API_KEYto your key from RapidAPI. The free Base plan gets 500 requests per month.
Install dependencies:
pnpm install
Start a development server:
pnpm dev
wrangler.jsonc gives local development a D1 database (DB) and an R2 bucket (PROJECTS), stored under .wrangler/state. It's never deployed: pnpm dev, pnpm preview and wrangler dev use it, and its Worker name (temperature-blanket-local) matches no deployed Worker. Its main and assets match production's, so pnpm build makes a Workers build locally too. The site, temperature-blanket.com, is the temperature-blanket Worker, built from main and configured by wrangler.production.jsonc (its header says where build variables, runtime vars and secrets live). For a few weeks after launch it also answers at next.temperature-blanket.com, where the version 7 beta was, to move projects saved only in a browser there to the main site. Older versions are archived as archive-vN branches of the Pages project, at archive-vN.temperature-blanket.com.
Apply database migrations (from migrations/) to the local database:
pnpm db:migrate:local
It also enables dev-only routes, which return 404 anywhere ENABLE_DEV_ROUTES isn't "true":
/api/dev/platformchecks the D1 and R2 bindings./api/dev/outbox?to=<address>lists emails "sent" by the fake sender (EMAIL_SENDER=dev-outbox), which stores them in the local R2 bucket instead of sending.
Accounts use Better Auth (pinned to an exact version) on D1, with sign-in by Google; there are no passwords. Emailed sign-in codes exist only where EMAIL_SIGN_IN=true (local dev and e2e, via wrangler.jsonc), so production sends no email. Its API is /api/auth/*, loaded only for those requests. The UI (/auth/sign-in, /account and the Account link) is built in only when PUBLIC_ACCOUNTS_ENABLED=true at build time; pnpm test:e2e:cloudflare builds with it on.
Server settings, read from the Cloudflare environment (local values are in wrangler.jsonc):
| Variable | Purpose |
|---|---|
ACCOUNTS_ENABLED |
"true" turns on /api/auth/*; anything else returns 404 |
BETTER_AUTH_SECRET |
At least 32 characters; signs session cookies. Set as an encrypted secret in production |
AUTH_ALLOWED_HOSTS |
Comma-separated hosts the app is served on, e.g. temperature-blanket.com or *.<project>.pages.dev for previews |
AUTH_PROTOCOL |
https (default), http, or auto |
EMAIL_SIGN_IN |
"true" turns on emailed sign-in codes (and the email settings below). Leave unset in production: Google is then the only sign-in, and required |
EMAIL_SENDER |
resend, or dev-outbox locally (only allowed where ENABLE_DEV_ROUTES is "true", since anyone can read the outbox). Anything else turns accounts off with a 503 |
RESEND_API_KEY, EMAIL_FROM |
For resend: an API key (as a secret) and the from-address, e.g. Temperature Blanket <[email protected]> |
GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET |
Turns on โContinue with Googleโ; required unless EMAIL_SIGN_IN is on. Redirect URI: <site>/api/auth/callback/google |
ACCOUNTS_SIGNUP_LIMIT |
Optional: the most accounts there may be. Unset means no limit, 0 closes sign-ups. Existing accounts keep signing in either way |
ACCOUNTS_CODE_LIMIT_PER_IP |
Optional: emailed codes one IP address may request an hour, for any addresses (default 10). Each address also gets at most 5 an hour |
EMAIL_DAILY_LIMIT |
Optional: emails Resend may send per UTC day (default 95, under the free plan's 100 a day and 3,000 a month). Past it, code requests say so (503 EMAIL_LIMIT_REACHED) |
TURNSTILE_SECRET_KEY |
Also checks signed-out code requests (with PUBLIC_TURNSTILE_SITE_KEY at build time). Without it, signed-out email sign-in is refused; Google still works |
Secrets for local development (for example real Google credentials) go in .dev.vars, which wrangler reads and git ignores.
Saved projects, palettes and some preferences sync to the signed-in account through /api/sync (metadata, palettes and preferences in D1, gzipped project JSON in R2; see src/lib/sync/protocol.ts). The server needs SYNC_ENABLED=true and the PROJECTS R2 binding; every account may sync.
To try accounts in the dev server, run pnpm dev:accounts (pnpm dev with PUBLIC_ACCOUNTS_ENABLED=true). No real email is sent: open /api/dev/outbox?to=<email> to read the code. Email sign-in needs PUBLIC_TURNSTILE_SITE_KEY=1x00000000000000000000AA in .env (the test site key that pairs with the test secret in wrangler.jsonc). It works over HTTPS on the tailnet too (AUTH_ALLOWED_HOSTS allows *.ts.net:5173). For Google, put GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET in .dev.vars, add https://<host>:5173/api/auth/callback/google as a redirect URI on the Google client, and restart the dev server.
After changing Better Auth plugins or options, generate the matching migration and apply it:
node scripts/generate-auth-migration.ts <name> pnpm db:migrate:local
First build the app
pnpm build
Unit tests (for functions)
pnpm test:unit
Integration tests (for the yarn colorway api route)
pnpm test:integration
End-to-end tests (for pages and ui flows)
pnpm test:e2e
End-to-end tests against the Cloudflare build under wrangler dev, which serves it as the deployed Worker does (static files and _redirects before the Worker) with the local D1 and R2 bindings (also checks every prerendered page is served and no file stands in for an API route)
pnpm test:e2e:cloudflare
Run all tests (unit, integration, and end-to-end)
pnpm testThanks for the support and feedback from users like you!
Temperature-blanket.com gets data from several APIs:
-
GeoNames for location data
-
Open-Meteo for weather data
-
Meteostat for weather data
Temperature-blanket.com uses a backend database in the form of a headless Wordpress site on a separate domain to store user-created gallery pages.
View Details
โน๏ธ The information below is intended for documentation only. You can test and develop this project locally without setting up your own backend database.
Here are the steps for setting up the headless Wordpress site:
- Install Wordpress on a separate domain.
- I use the following plugins
- EWWW Image Optimizer - To compress and optimize project preview images
- Redirection - To redirect the headless Wordpress home page to the temperature-blanket.com site, and to redirect project pages to their corresponding gallery pages on temperature-blanket.com.
- Temperature Blanket Custom Plugin - I created a Wordpress plugin which handles the necessary setup and allows for creation of project gallery pages through a custom REST endpoint. The source code for this plugin is not public, but if you are interested you can reach out to me.
- Wordfence - For general site security
- Wordpress Popular Posts - For tracking popular project gallery pages
- WP-GraphQL - For interacting with the Wordpress backend
- Add the following line to
wp-config.php:
define('PROJECT_CREATION_AUTH_KEY', 'auth_key');
- In this project's
.envfile,SECRET_WORDPRESS_PROJECT_CREATION_AUTH_KEYshould be the same'auth_key'value. Without the correct auth key, the Wordpress site won't accept POST requests for new project gallery pages.
๐ก When developing locally, POST requests to create new temperature blanket project gallery pages will be rejected. This is normal, because you don't have the necessary authentication key.
Settings and user preferences are stored in the browser's Local Storage.
View Details
| Key Name | Description | Default Value | Possible Values | Version Added* |
|---|---|---|---|---|
| preferences | User preferences object | { disableToastAnalytics: false, layout: 'list', seasons: [...DEFAULT_SEASONS], theme: { id: 'classic', mode: 'system', roundness: 'pill', spacing: 'normal', textScale: 'normal', headingStyle: 'classic' }, units: 'imperial'} |
LocalStatePreferencesType |
5.0.0 |
| [/weather]units | Units for the weather forecast page | imperial |
imperial, metric |
< 3.28.3 |
| [/weather]hour_format | Time format for the weather forecast page | 12 |
12, 24 |
< 3.28.3 |
| [/weather]locations | Locations the user has added for the weather forecast page | [] |
array of Location objects |
< 3.28.3 |
| preferences_sync | When each synced preference last changed on this device and which of those changes the signed-in account has, so the newest change to each wins (changes are noted signed out too) | none | PreferencesSyncState |
7.0.0 |
| tb_gallery_blocks | Gallery pages whose publishers were blocked while signed out ({ postId, kind, title, createdAt }[]), so their pages are left out; added to the account at sign-in and then removed |
none | GalleryBlock[] |
7.1.0 |
| tb_account | The signed-in person's account ID, name, email and picture, so the navigation can show them and saved projects know their account. Removed when the session ends | none | AccountSummary |
7.0.0 |
| tb_site_owner | The site owner's account ID, set once /gallery/reports has loaded for them, so only their devices ask for the new-reports badge |
none | account ID (owner-reports) | 7.1.0 |
| yarn_uses | How many times colors from each yarn have been saved (from Choose Colorways, Random, and From an Image), and the yarns not to suggest again, to suggest making a favorite yarn the default. Kept on this device only | none | YarnUsesState |
7.0.0 |
| accounts_intro | Whether the signed-out account button's "New" dot has been used, so it introduces accounts (in beta) once. Kept on this device only | none | AccountsIntroState |
7.0.0 |
| whats_new_seen | The last version whose news has been seen (dismissed, or What's New opened), so the "Version 7" line and the dot by What's New show once. Set to the current version on a first visit | none | string, e.g. '7.0.0' (whats-new) |
7.0.0 |
| beta_warning_dismissed | Whether "Don't show this again" was ticked in the beta's warning on load (next.temperature-blanket.com only). Kept on this device only | none | boolean (BetaWarning) |
7.0.0 |
| beta_feedback_time | How long the beta has been in view, over every visit (milliseconds), so its one question ("How's the beta working for you?") waits a few minutes (next.temperature-blanket.com only). Kept on this device only | none | a number (beta-feedback-toast) | 7.0.0 |
| beta_feedback_asked | Set once the beta's one question has shown, or feedback was sent, so it never asks again (next.temperature-blanket.com only). Kept on this device only | none | 'true' (beta-feedback-toast) |
7.0.0 |
| welcome_checked | Account IDs already checked for a welcome in this browser, so the server is asked once whether the account is brand new (see welcome) | none | string[] |
7.0.0 |
| my_library_section | Which side of My Library was open last (Projects or Yarn Palettes), so the sidebar's My Library link goes back to it. Kept on this device only | none | 'projects', 'palettes' (library-section) |
7.0.0 |
preferences.theme fields:
| Field | Description | Default | Options |
|---|---|---|---|
id |
Color palette | 'classic' |
'classic', 'crimson', 'hamlindigo', 'modern', 'rocket', 'legacy' |
mode |
Light/dark mode | 'system' |
'light', 'dark', 'system' |
roundness |
Button/container corner radius | 'pill' |
'sharp', 'rounded', 'pill' |
spacing |
Layout density | 'normal' |
'compact', 'normal', 'relaxed' |
textScale |
Typographic scale ratio | 'normal' |
'small', 'normal', 'large' |
headingStyle |
Heading font-variation-settings | 'classic' |
'classic', 'playful', 'refined' |
preferences.paletteImage fields (the palette image export's last settings, except its layout and space between colors, which start as the View menu's each time; missing until a setting is first changed, and filled in from the defaults when read โ 7.0.0):
| Field | Description | Default | Options |
|---|---|---|---|
shape |
The image's size | 'fit' |
'fit', 'square', 'portrait', 'landscape' |
background |
Background color | 'light' |
'light', 'dark' |
fill |
Colors fill their cell; off shows a round swatch | the View โบ Fill with color setting when first opened | true, false |
labels |
What's written on each color | { yarn: true, colorway: true, hex: false, range: true, number: false } |
booleans |
preferences.pdf fields (the PDF's last choices, saved when it's downloaded; its layout, Fill with color, Space between and Days in ranges start as the View menu has them each time, and which gauges to include starts as all of them; missing until the first PDF, and filled in from the defaults when read โ 7.0.0):
| Field | Description | Default | Options |
|---|---|---|---|
pageSize |
Paper size | 'letter' in the US, Canada and nearby, else 'a4' |
'a4', 'letter' |
summary |
A first page with the project and its preview | true |
true, false |
additionalColors |
The preview's border and accent colors | true |
true, false |
hex |
Each color's HTML color code | false |
true, false |
weatherDataParams |
The weather table's columns; none leaves it out | ['tmax', 'tavg', 'tmin'] |
weather parameter ids |
preferences.effects fields (motion, set in the Preferences dialog; missing until a setting is first changed, and filled in from the defaults when read โ 7.0.0):
| Field | Description | Default | Options |
|---|---|---|---|
motion |
'reduce' turns off decorative animations; 'system' follows the device's setting |
'system' |
'system', 'reduce' |
preferences.defaultYarn (7.0.0): the yarn chosen first where none is, as {brandId}-{yarnId}, set in the Preferences dialog or with "Set as Default Yarn". Missing or '' for none (before, it was kept only until the page was reloaded).
preferences.fillColor (7.0.0): View โบ Fill with color, offered for yarn colorway cards and rows (the finder, Choose Colorways, Change Color) and a palette's colors. true fills each card or row with its yarn's color; missing (off) until first changed.
preferences.itemSpacing (7.0.0): View โบ Space between, offered where Fill with color is, kept for each layout: { grid?: boolean, list?: boolean }, true for cards or rows apart, false for one block with only its outer corners rounded. Missing until first changed (apart in a grid, together in a list).
preferences.myProjectsLayout (7.0.0): My Projects' View menu, 'grid' (projects and palettes as cards side by side) or 'list' (one per row); missing (grid) until first changed.
preferences.weatherShowColors (7.0.0): Show Colors, one setting for every weather table (the Weather step's, Edit Weather Data, View All Changes, a range's days and the Daytime Rows stitches). true shows a swatch and "Color 3" beside each value; missing (off) until first changed.
Synced to the account while signed in (#lib/sync/preferences): defaultYarn, theme.id, theme.mode, theme.roundness and theme.headingStyle; the newest change to each wins. The rest stay on the device: text size, spacing, effects, layout, myProjectsLayout, fillColor, itemSpacing, weatherShowColors, units and seasons (every project link carries its own units and seasons).
Backwards compatibility: Old
preferencesobjects withoutroundness/spacing/textScale/headingStylefields automatically receive defaults on next page load. No data is lost.
*Items with a < before the version means sometime before that version, I'm not sure exactly when because I wasn't keeping track before version 3.28.3.
Kept only for the open tab.
| Key Name | Description | Default Value | Possible Values | Version Added |
|---|---|---|---|---|
| just_trashed_project | The project just moved to the Trash from the Project menu, so the new project's page can offer Undo. Removed once that page reads it | none | JustTrashed |
7.0.0 |
| beta_warning_shown | Set once the beta's warning has shown in this tab (next.temperature-blanket.com only), so it shows once a visit | none | '1' (open-beta-warning) |
7.0.0 |
| tb_new_reports | The site owner's count of gallery pages with new reports and when it was asked, so the badge asks at most every 10 minutes | none | { at, count } (owner-reports) |
7.1.0 |
User's saved projects and saved palettes are stored in the browser's IndexedDB.
View Details
| Key Name | Description | Default Value | Possible Values | Version Added |
|---|---|---|---|---|
| projects_index | An index of projects the user has saved | [] |
array of LocalStorageProjectIndexItem objects |
5.35.0 |
| p_{id} | An individual saved project | not set | LocalStorageProject objects, keyed by project id |
5.35.0 |
| saved_palettes | Palettes the user saved (deleted ones, in the Trash, are kept with deletedAt for 30 days). Signed in, each carries sync (owner, revision, changed here); one deleted for good is kept as a purged record until the account knows |
not set | array of SavedPalette objects |
7.0.0 |
| projects_trash | Projects moved to the Trash, each with its index entry, data, list position and deletedAt; kept 30 days |
not set | array of TrashedProject objects |
7.0.0 |
| sync_account_{userId} | Sync bookkeeping for a signed-in account on this device: the last server revision seen, deletions waiting to reach the server, projects deleted for good meanwhile (pendingPurges), whether the "add your projects" prompt was shown |
not set | AccountSyncState |
7.0.0 |
| thumb_{id} | A small picture (JPEG data URL) of a saved project's preview, for its card on My Projects, with the project link it was drawn from ({ href, image }). Taken when the planner saves or opens the project; kept in this browser only (not synced), and deleted with the project for good |
not set | StoredThumbnail (src/lib/storage/thumbnails.ts) |
7.0.0 |
Project IDs are opaque strings (^[A-Za-z0-9-]{1,64}$), carried in the URL as ?project=<id>. New projects currently use the millisecond timestamp of when the app was loaded, but code must not rely on that: use the stored createdAt for the creation date.
p_{id} fields added after 5.35.0:
| Field | Description | Version Added |
|---|---|---|
createdAt |
When the project was first created (ISO 8601, UTC); kept across saves | 7.0.0 |
name |
The name given on My Projects, kept across saves (also on the projects_index entry's meta); when missing, title is shown |
7.0.0 |
weatherDays |
About its weather days (StoredWeatherDays): each location's last day got (fetchedThrough), the day its days were all got (fetchedAt, by a search of every day, or the gallery page's last update; missing before), days got while early (early, <location>|YYYY-MM-DD โ the day got) and newer values kept over by Check for Updates (declined, metric). When missing, each location's last day with values is used. A saved project always opens with its saved days |
7.0.0 |
progress |
How far the blanket is made (StoredProgress): madeThrough (YYYY-MM-DD, every location's days through it; null: not started) and show (Show Progress in the preview: days not made yet dimmed). Synced with the project; never in its link, so a link or a copy starts at Not started. Missing until set |
7.0.0 |
projects_index item fields added after 5.35.0:
| Field | Description | Version Added |
|---|---|---|
sync |
Set once the project belongs to an account: owner account ID, server revision, whether it changed since the last upload, last error (ProjectSyncState). Absent on projects of this browser only |
7.0.0 |
updatedAt |
When a project of this browser only was last saved or renamed here (ms), so auto-save can tell when another tab saved over it; absent on projects saved before, and on account projects (see sync.updatedAt) |
7.0.0 |
meta.made |
How much of the project is made (percent, from progress.madeThrough), for its My Library card; absent until progress is set |
7.0.0 |
Backwards compatibility: Changes to IndexedDB are additive only. Projects without
createdAtfall back to the time in their legacy timestamp ID, and getcreatedAtthe next time they're saved.
