mirror of https://github.com/sveltejs/svelte
commit
a6a8ffd0f8
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,13 @@
|
||||
NODE_ENV=
|
||||
|
||||
PORT=
|
||||
BASEURL=
|
||||
PORT=3000
|
||||
BASEURL=http://localhost:3000
|
||||
GITHUB_CLIENT_ID=
|
||||
GITHUB_CLIENT_SECRET=
|
||||
MAPBOX_ACCESS_TOKEN=
|
||||
VITE_MAPBOX_ACCESS_TOKEN=
|
||||
|
||||
PGHOST=hostname
|
||||
PGPORT=port
|
||||
PGHOST=localhost
|
||||
PGPORT=5432
|
||||
PGUSER=username
|
||||
PGPASSWORD=password
|
||||
PGDATABASE=database_name
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "stable"
|
||||
env:
|
||||
global:
|
||||
- BUILD_TIMEOUT=10000
|
||||
install:
|
||||
- npm install
|
||||
- npm install cypress
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
version: "{build}"
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
init:
|
||||
- git config --global core.autocrlf false
|
||||
|
||||
build: off
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
# node.js
|
||||
- nodejs_version: stable
|
||||
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
- npm install
|
||||
@ -0,0 +1,99 @@
|
||||
---
|
||||
title: What's new in Svelte: October 2021
|
||||
description: A whole year of "What's new in Svelte"
|
||||
author: Daniel Sandoval
|
||||
authorURL: https://desandoval.net
|
||||
---
|
||||
|
||||
Hey y'all 👋 It's been 1 year since "What's new in Svelte" started being cross-posted to the Svelte blog. I wanted to take this moment at the top to thank all of you for reading and for all the contributors every month. From the maintainers to everyone who posts their work in the Discord and Reddit, it's amazing to witness all the effort that goes into making the Svelte community great.
|
||||
|
||||
Keep up the good work, everyone! Now, let's dive into this month's news...
|
||||
|
||||
## New around Svelte
|
||||
|
||||
- New additions to Svelte's export map now expose no-op versions of lifecycle functions for SSR (Svelte **3.43.0**)
|
||||
- Custom components with a `src` attribute no longer break `svelte-native` builds (Svelte **3.42.4**)
|
||||
- Svelte plugin users without [the TypeScript plugin](https://www.npmjs.com/package/typescript-svelte-plugin) enabled will now be prompted to enable it. It enhances TypeScript and JavaScript files with additional intellisense to interact with Svelte files. [Please leave feedback](https://github.com/sveltejs/language-tools/issues/580) if you are using it (Svelte extensions **105.4.0**)
|
||||
- Event modifiers have been added to intellisense as autocomplete and hover info (Svelte extensions **105.4.0**)
|
||||
- TypeScript users no longer have to strictly separate type imports and value imports when using Svelte version 3.39 or higher and `svelte-preprocess` version 4.9.5 or higher. This means you can now write `import { MyInterface, myValue } from './somewhere'` instead of `import type { MyInterface } from './somewhere'; import { myValue } from './somewhere'`. Huge thanks to community member [@SomaticIT](https://github.com/SomaticIT) who mainly implemented this!
|
||||
|
||||
For a full list of features and bug fixes, check out the [Svelte changelog](https://github.com/sveltejs/svelte/blob/master/CHANGELOG.md).
|
||||
|
||||
## SvelteKit Updates
|
||||
|
||||
Nearly 100 PRs committed again this past month, but there's still lots to do and Svelte maintainers are [looking for help getting SvelteKit to 1.0](https://github.com/sveltejs/kit/issues/2100). Antony said it well in a [recent comment](https://github.com/sveltejs/kit/issues/2100#issuecomment-895446285) on the issue:
|
||||
|
||||
> If you think you are too n00b to contribute (you're not), then add tests, or write tests for the feature you want to add, before you add it! Start small, and learn the codebase that way.
|
||||
|
||||
If you'd like to help, please consider working on any of the [1.0 milestone issues labeled with "help wanted"](https://github.com/sveltejs/kit/issues?q=is%3Aopen+is%3Aissue+milestone%3A1.0+label%3A%22help+wanted%22).
|
||||
|
||||
Notable SvelteKit improvements this month include...
|
||||
|
||||
- Service workers are now allowed to access files using the `$lib` alias ([#2326](https://github.com/sveltejs/kit/pull/2326))
|
||||
- Svelte libraries should now work out-of-the-box without any Vite configuration ([#2343](https://github.com/sveltejs/kit/pull/2343))
|
||||
- Improvements to package exports field ([#2345](https://github.com/sveltejs/kit/pull/2345) and [#2327](https://github.com/sveltejs/kit/pull/2327))
|
||||
- [breaking] The `prerender.pages` config option has been renamed to `prerender.entries` ([#2380](https://github.com/sveltejs/kit/pull/2380))
|
||||
- A new generic argument has beend added to allow typing Body from hooks ([#2413](https://github.com/sveltejs/kit/pull/2413))
|
||||
- The `svelte` field will be added to package.json when running the package command ([#2431](https://github.com/sveltejs/kit/pull/2431))
|
||||
- [breaking] The `context` parameter of the load function was renamed to `stuff` ([#2439](https://github.com/sveltejs/kit/pull/2439))
|
||||
- Added an `entryPoint` option for building a custom server with `adapter-node` ([#2414](https://github.com/sveltejs/kit/pull/2414))
|
||||
- `vite-plugin-svelte` improved support for [useVitePreprocess](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#usevitepreprocess), which uses Vite to automatically preprocess TypeScript, PostCSS, Scss, etc in Svelte components ([#173](https://github.com/sveltejs/vite-plugin-svelte/pull/173))
|
||||
|
||||
To see all updates to SvelteKit, check out the [SvelteKit changelog](https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md).
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Community Showcase
|
||||
|
||||
**Apps & Sites**
|
||||
- [radiofrance](https://www.radiofrance.fr/) just migrated their website to SvelteKit
|
||||
- [FLAYKS](https://flayks.com/) is the portfolio site for Félix Péault made with SvelteKit, Sanity, and Anime.js
|
||||
- [hirehive](https://www.hirehive.com/) is a candidate and job tracking site
|
||||
- [Microsocial](https://microsocial.xyz/) is an experimental Peer-to-Peer Social Platform
|
||||
- [Dylan Ipsum](https://www.dylanlyrics.app/) is a random text generator to replace lorem ipsum with Bob Dylan lyrics
|
||||
- [Chip8 Svelte](https://github.com/mikeyhogarth/chip8-svelte) is a CHIP-8 emulator frontend, built on top of CHIP8 Typescript
|
||||
|
||||
**Looking for a Svelte project to work on? Interested in helping make Svelte's presence on the web better?** Check out [the list of open issues](https://github.com/svelte-society/sveltesociety-2021/issues) if you'd like to contribute to the Svelte Society rewrite in SvelteKit.
|
||||
|
||||
**Podcasts Featuring Svelte**
|
||||
- [Syntax Podast: From React to SvelteKit](https://podcasts.apple.com/us/podcast/from-react-to-sveltekit/id1253186678?i=1000536276106) Scott talks with Wes about moving Level Up Tutorials from React to SvelteKit — why he did it, how, benefits, things to watch out for, and more!
|
||||
- [Web Rush Podcast: Svelte Tools and Svelte Society](https://www.webrush.io/episodes/episode-150-svelte-tools-and-svelte-society) Kevin Åberg Kultalahti talks about what Svelte Society is, what he's excited about with Svelte, how important documentation is to any product, and much _much_ more
|
||||
- [Svelte: The Compiled Future of Front End](https://www.arahansen.com/the-compiled-future-of-front-end/) details the history of component-based frontends and how a compiler changes everything
|
||||
- [Svelte Radio: Contributing to Svelte with Martin 'Grygrflzr' Krisnanto Putra](https://share.transistor.fm/s/10aa305c) Grygrflzr shares his journey to becoming a maintainer and his views on React, Vite and a host of other things
|
||||
- [Svelte Radio: Routify 3 with Jake and Willow](https://share.transistor.fm/s/10aa305c) the Svelte Radio crew sits down with the maintainers of Routify and discusses the just-released Routify 3
|
||||
- [JS Party: 1Password](https://twitter.com/geoffrich_/status/1441816829853253640?s=20) mentioned on the latest episode of The Changelog's JS Party that they use Svelte to power their in-page suggestions
|
||||
|
||||
**Educational Content**
|
||||
- [How I built a blog with Svelte and SvelteKit](https://fantinel.dev/blog-development-sveltekit/) is an introduction to Svelte, SvelteKit and Progressive Enhancement with code examples
|
||||
- [I built a decentralized chat dapp](https://www.youtube.com/watch?v=J5x3OMXjgMc) is a tutorial on how to use popular web3 technologies like GUN to build a decentralized web app (dapp)
|
||||
- [Writing a Svelte Store with TypeScript](https://javascript.plainenglish.io/writing-a-svelte-store-with-typescript-22fa1c901a4) is a deep dive into writing Svelte stores with TypeScript
|
||||
- [How Svelte scopes component styles](https://geoffrich.net/posts/svelte-scoped-styles/) explains scoping using classes and more complex CSS specifiers
|
||||
- [SvelteKit Hooks](https://www.youtube.com/watch?v=RarufLoEL08) shows how to use hooks.js in Sveltekit.. When you're done, check out [Part 2](https://www.youtube.com/watch?v=RmIBG3G0-VY)
|
||||
- [An early look at SvelteKit](https://www.infoworld.com/article/3630395/an-early-look-at-sveltekit.html) is a post from Infoworld walking through the features and onboarding of SvelteKit
|
||||
|
||||
**Libraries, Tools & Components**
|
||||
- [sveltekit-netlify-cms](https://github.com/buhrmi/sveltekit-netlify-cms) is a SvelteKit skeleton app configured for use with Netlify CMS
|
||||
- [SvelteFireTS](https://github.com/jacobbowdoin/sveltefirets) is a SvelteKit + Typescript + Firebase library inspired by Fireship.io
|
||||
- [stores-x](https://github.com/Anyass3/stores-x) lets you use Svelte stores just like vueX
|
||||
- [sveltekit-snippets](https://github.com/stordahl/sveltekit-snippets) is a VSCode extension that provides snippets for common patterns in SvelteKit & Vanilla Svelte
|
||||
- [svelte-xactor](https://github.com/wobsoriano/svelte-xactor) is a middleware that allows you to easily convert your xactor machines into a global store that implements the store contract
|
||||
- [vite-plugin-pages-svelte](https://github.com/aldy505/vite-plugin-pages-svelte) is a vite plugin for automatic filesystem-based routing
|
||||
- [sveltio](https://www.npmjs.com/package/sveltio) is a Svelte wrapper for valtio - a proxy-state library
|
||||
- [svelte-transition-classes](https://github.com/rmarscher/svelte-transition-classes) is a custom Svelte transition for adding and swapping CSS classes
|
||||
- [Svelte-Boring-Avatars](https://github.com/paolotiu/svelte-boring-avatars) is Svelte port of the popular [Boring Avatars](https://github.com/boringdesigners/boring-avatars) React project
|
||||
- [Svelte DataTables](https://github.com/homescriptone/svelte-datatables) brings DataTable, a popular JavaScript library allowing you to easily display your data in a user-friendly table, into your Svelte project.
|
||||
- [focus-svelte](https://github.com/chanced/focus-svelte) is a focus trap for Svelte with zero dependencies
|
||||
- [filedrop-svelte](https://github.com/chanced/filedrop-svelte) is a file dropzone action & component for Svelte
|
||||
|
||||
|
||||
Check out the community site [sveltesociety.dev](https://sveltesociety.dev/templates/) for more templates, adders and adapters from across the Svelte ecosystem.
|
||||
|
||||
|
||||
## Before you go, answer the call for speakers!
|
||||
|
||||
Svelte Summit Fall 2021 (happening 20 November 2021) is looking for speakers. Submit your talk propsoal before 30 October... all are welcome to present and attend.
|
||||
|
||||
### More info on the [sessionize site](https://sessionize.com/svelte-summit-fall-2021/)
|
||||
|
||||
Can't wait for the summit? Join us on [Reddit](https://www.reddit.com/r/sveltejs/) or [Discord](https://discord.com/invite/yy75DKs)!
|
||||
@ -0,0 +1,15 @@
|
||||
version: "3.0"
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13.4
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
- POSTGRES_DB=${PGDATABASE}
|
||||
- POSTGRES_USER=${PGUSER}
|
||||
- POSTGRES_PASSWORD=${PGPASSWORD}
|
||||
adminer:
|
||||
image: adminer
|
||||
restart: always
|
||||
ports:
|
||||
- "4000:8080"
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,122 +0,0 @@
|
||||
import 'dotenv/config';
|
||||
import babel from '@rollup/plugin-babel';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import json from '@rollup/plugin-json';
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import svelte from 'rollup-plugin-svelte';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import config from 'sapper/config/rollup.js';
|
||||
import pkg from './package.json';
|
||||
|
||||
const mode = process.env.NODE_ENV;
|
||||
const dev = mode === 'development';
|
||||
const legacy = !!process.env.SAPPER_LEGACY_BUILD;
|
||||
|
||||
if (!dev && !process.env.MAPBOX_ACCESS_TOKEN) {
|
||||
throw new Error('MAPBOX_ACCESS_TOKEN is missing. Please add the token in the .env file before generating the production build.');
|
||||
}
|
||||
|
||||
const onwarn = (warning, onwarn) => (warning.code === 'CIRCULAR_DEPENDENCY' && /[/\\]@sapper[/\\]/.test(warning.message)) || onwarn(warning);
|
||||
const dedupe = importee => importee === 'svelte' || importee.startsWith('svelte/');
|
||||
|
||||
export default {
|
||||
client: {
|
||||
input: config.client.input(),
|
||||
output: config.client.output(),
|
||||
plugins: [
|
||||
replace({
|
||||
'process.browser': true,
|
||||
'process.env.NODE_ENV': JSON.stringify(mode),
|
||||
'process.env.MAPBOX_ACCESS_TOKEN': JSON.stringify(process.env.MAPBOX_ACCESS_TOKEN)
|
||||
}),
|
||||
svelte({
|
||||
compilerOptions: {
|
||||
dev,
|
||||
hydratable: true
|
||||
}
|
||||
}),
|
||||
resolve({
|
||||
browser: true,
|
||||
dedupe
|
||||
}),
|
||||
commonjs(),
|
||||
json(),
|
||||
|
||||
legacy && babel({
|
||||
extensions: ['.js', '.mjs', '.html', '.svelte'],
|
||||
babelHelpers: 'runtime',
|
||||
exclude: ['node_modules/@babel/**'],
|
||||
presets: [
|
||||
['@babel/preset-env', {
|
||||
targets: '> 0.25%, not dead'
|
||||
}]
|
||||
],
|
||||
plugins: [
|
||||
'@babel/plugin-syntax-dynamic-import',
|
||||
['@babel/plugin-transform-runtime', {
|
||||
useESModules: true
|
||||
}]
|
||||
]
|
||||
}),
|
||||
|
||||
!dev && terser({
|
||||
module: true
|
||||
})
|
||||
],
|
||||
|
||||
preserveEntrySignatures: false,
|
||||
onwarn
|
||||
},
|
||||
|
||||
server: {
|
||||
input: config.server.input(),
|
||||
output: config.server.output(),
|
||||
plugins: [
|
||||
replace({
|
||||
'process.browser': false,
|
||||
'process.env.NODE_ENV': JSON.stringify(mode)
|
||||
}),
|
||||
svelte({
|
||||
compilerOptions: {
|
||||
dev,
|
||||
generate: 'ssr',
|
||||
hydratable: true
|
||||
},
|
||||
emitCss: false
|
||||
}),
|
||||
resolve({
|
||||
dedupe
|
||||
}),
|
||||
commonjs(),
|
||||
json()
|
||||
],
|
||||
external: [
|
||||
'yootils',
|
||||
'codemirror',
|
||||
...Object.keys(pkg.dependencies || {}).concat(
|
||||
require('module').builtinModules || Object.keys(process.binding('natives'))
|
||||
)
|
||||
],
|
||||
|
||||
preserveEntrySignatures: 'strict',
|
||||
onwarn
|
||||
},
|
||||
|
||||
serviceworker: {
|
||||
input: config.serviceworker.input(),
|
||||
output: config.serviceworker.output(),
|
||||
plugins: [
|
||||
resolve(),
|
||||
replace({
|
||||
'process.browser': true,
|
||||
'process.env.NODE_ENV': JSON.stringify(mode)
|
||||
}),
|
||||
commonjs(),
|
||||
!dev && terser()
|
||||
],
|
||||
|
||||
preserveEntrySignatures: false,
|
||||
onwarn
|
||||
}
|
||||
};
|
||||
@ -1,4 +1,4 @@
|
||||
const sh = require('shelljs');
|
||||
import sh from 'shelljs';
|
||||
|
||||
sh.rm('-rf', 'static/workers');
|
||||
sh.cp('-r', 'node_modules/@sveltejs/svelte-repl/workers', 'static');
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
import 'dotenv/config';
|
||||
import fs from 'fs';
|
||||
import fetch from 'node-fetch';
|
||||
import Jimp from 'jimp';
|
||||
import { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
|
||||
const force = process.env.FORCE_UPDATE === 'true';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
process.chdir(__dirname);
|
||||
|
||||
const outputFile = `../src/routes/_donors.js`;
|
||||
if (!force && fs.existsSync(outputFile)) {
|
||||
console.info(`[update/donors] ${outputFile} exists. Skipping`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const SIZE = 64;
|
||||
|
||||
async function main() {
|
||||
const res = await fetch('https://opencollective.com/svelte/members/all.json');
|
||||
const donors = await res.json();
|
||||
|
||||
const unique = new Map();
|
||||
donors.forEach(d => unique.set(d.profile, d));
|
||||
|
||||
let backers = [...unique.values()]
|
||||
.filter(({ role }) => role === 'BACKER')
|
||||
.sort((a, b) => b.totalAmountDonated - a.totalAmountDonated);
|
||||
|
||||
const included = [];
|
||||
for (let i = 0; i < backers.length; i += 1) {
|
||||
const backer = backers[i];
|
||||
console.log(`${i} / ${backers.length}: ${backer.name}`);
|
||||
|
||||
try {
|
||||
const image_data = await fetch(backer.image);
|
||||
const buffer = await image_data.arrayBuffer();
|
||||
const image = await Jimp.read(buffer);
|
||||
image.resize(SIZE, SIZE);
|
||||
included.push({ backer, image });
|
||||
} catch( err) {
|
||||
console.log(`Skipping ${backer.name}: no image data`);
|
||||
}
|
||||
}
|
||||
|
||||
const sprite = new Jimp(SIZE * included.length, SIZE);
|
||||
for (let i = 0; i < included.length; i += 1) {
|
||||
sprite.composite(included[i].image, i * SIZE, 0);
|
||||
}
|
||||
|
||||
await sprite.quality(80).write(`../static/donors.jpg`);
|
||||
// TODO: Optimizing the static/donors.jpg image should probably get automated as well
|
||||
console.log('remember to additionally optimize the resulting /static/donors.jpg image file via e.g. https://squoosh.app ');
|
||||
|
||||
const str = `[\n\t${included.map(a => `${JSON.stringify(a.backer.name)}`).join(',\n\t')}\n]`;
|
||||
|
||||
fs.writeFileSync(outputFile, `export default ${str};`);
|
||||
}
|
||||
|
||||
main();
|
||||
@ -1,8 +1,9 @@
|
||||
const sh = require('shelljs');
|
||||
import sh from 'shelljs';
|
||||
|
||||
sh.env['FORCE_UPDATE'] = process.argv.includes('--force=true');
|
||||
|
||||
Promise.all([
|
||||
sh.exec('node ./scripts/get_contributors.js'),
|
||||
sh.exec('node ./scripts/get_donors.js'),
|
||||
sh.exec('node ./scripts/update_template.js')
|
||||
]);
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
<!doctype html>
|
||||
<html lang='en' class="theme-default typo-default">
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<meta name='theme-color' content='#ff3e00'>
|
||||
|
||||
<base href='/'>
|
||||
|
||||
<link rel='stylesheet' href='global.css'>
|
||||
<link rel='stylesheet' href='prism.css'>
|
||||
<link rel='manifest' href='manifest.json'>
|
||||
<link rel='icon' type='image/png' href='favicon.png'>
|
||||
|
||||
<meta name='twitter:card' content='summary_large_image'>
|
||||
<meta name='twitter:site' content='@sveltejs'>
|
||||
<meta name='twitter:creator' content='@sveltejs'>
|
||||
<meta name='twitter:image' content='https://svelte.dev/images/twitter-card.png'>
|
||||
<meta name='og:image' content='https://svelte.dev/images/twitter-card.png'>
|
||||
|
||||
%svelte.head%
|
||||
</head>
|
||||
<body>
|
||||
<div id='svelte'>%svelte.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,6 +0,0 @@
|
||||
import '@sveltejs/site-kit/base.css';
|
||||
import * as sapper from '@sapper/app';
|
||||
|
||||
sapper.start({
|
||||
target: document.querySelector('#sapper')
|
||||
});
|
||||
@ -0,0 +1,31 @@
|
||||
// need to do this first before importing database, etc.
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
import * as cookie from 'cookie';
|
||||
import { get_user, sanitize_user } from './utils/auth';
|
||||
import { query } from './utils/db';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Handle} */
|
||||
export async function handle({ request, resolve }) {
|
||||
if (process.env['PGHOST']) {
|
||||
// this is a convenient time to clear out expired sessions
|
||||
query('delete from sessions where expiry < now()');
|
||||
|
||||
request.locals.cookies = cookie.parse(request.headers.cookie || '');
|
||||
request.locals.user = await get_user(request.locals.cookies.sid);
|
||||
}
|
||||
|
||||
const response = await resolve(request);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/** @type {import('@sveltejs/kit').GetSession} */
|
||||
export function getSession(request) {
|
||||
return request.locals.user
|
||||
? {
|
||||
user: sanitize_user(request.locals.user)
|
||||
}
|
||||
: {};
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<script>
|
||||
import donors from '../_donors.js';
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.donor {
|
||||
width: 2.4em;
|
||||
height: 2.4em;
|
||||
border-radius: 50%;
|
||||
text-indent: -9999px;
|
||||
display: inline-block;
|
||||
background: no-repeat url(/donors.jpg);
|
||||
background-size: auto 102%;
|
||||
margin: 0 0.5em 0.5em 0;
|
||||
border: 2px solid var(--second);
|
||||
}
|
||||
</style>
|
||||
|
||||
{#each donors as donor, i}
|
||||
<a
|
||||
class="donor"
|
||||
style="background-position: {(100 * i) / (donors.length - 1)}% 0"
|
||||
alt="{donor}"
|
||||
href="https://opencollective.com/svelte">
|
||||
{donor}
|
||||
</a>
|
||||
{/each}
|
||||
@ -1,26 +1,25 @@
|
||||
import send from '@polka/send';
|
||||
import { query } from '../../utils/db';
|
||||
import { query as db_query } from '../../utils/db';
|
||||
|
||||
export async function get(req, res) {
|
||||
if (req.user) {
|
||||
export async function get({ query, locals }) {
|
||||
if (locals.user) {
|
||||
const page_size = 100;
|
||||
const offset = req.query.offset ? parseInt(req.query.offset) : 0;
|
||||
const rows = await query(`
|
||||
const offset = query.get('offset') ? parseInt(query.get('offset')) : 0;
|
||||
const rows = await db_query(`
|
||||
select g.uid, g.name, coalesce(g.updated_at, g.created_at) as updated_at
|
||||
from gists g
|
||||
where g.user_id = $1
|
||||
order by id desc
|
||||
limit ${page_size + 1}
|
||||
offset $2
|
||||
`, [req.user.id, offset]);
|
||||
`, [locals.user.id, offset]);
|
||||
|
||||
rows.forEach(row => {
|
||||
row.uid = row.uid.replace(/-/g, '');
|
||||
});
|
||||
|
||||
const more = rows.length > page_size;
|
||||
send(res, 200, { apps: rows.slice(0, page_size), offset: more ? offset + page_size : null });
|
||||
return { body: { apps: rows.slice(0, page_size), offset: more ? offset + page_size : null }};
|
||||
} else {
|
||||
send(res, 401);
|
||||
return { status: 401 };
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
export const oauth = 'https://github.com/login/oauth';
|
||||
export const baseurl = process.env.BASEURL;
|
||||
export const baseurl = process.env['BASEURL'];
|
||||
export const secure = baseurl && baseurl.startsWith('https:');
|
||||
|
||||
export const client_id = process.env.GITHUB_CLIENT_ID;
|
||||
export const client_secret = process.env.GITHUB_CLIENT_SECRET;
|
||||
export const client_id = process.env['GITHUB_CLIENT_ID'];
|
||||
export const client_secret = process.env['GITHUB_CLIENT_SECRET'];
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
import send from '@polka/send';
|
||||
import * as cookie from 'cookie';
|
||||
import { secure } from './_config.js';
|
||||
import { delete_session } from '../../utils/auth.js';
|
||||
|
||||
export async function get(req, res) {
|
||||
await delete_session(req.cookies.sid);
|
||||
export async function get(request) {
|
||||
await delete_session(request.locals.cookies.sid);
|
||||
|
||||
send(res, 200, '', {
|
||||
return {
|
||||
headers: {
|
||||
'Set-Cookie': cookie.serialize('sid', '', {
|
||||
maxAge: -1,
|
||||
path: '/',
|
||||
httpOnly: true,
|
||||
secure
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
export function get(req, res) {
|
||||
res.writeHead(302, { Location: 'https://discord.gg/yy75DKs' });
|
||||
res.end();
|
||||
export function get() {
|
||||
return {
|
||||
status: 302,
|
||||
headers: { Location: 'https://discord.gg/yy75DKs' },
|
||||
};
|
||||
}
|
||||
@ -1,12 +1,13 @@
|
||||
import send from '@polka/send';
|
||||
import get_sections from './_sections.js';
|
||||
|
||||
let json;
|
||||
|
||||
export function get(req, res) {
|
||||
export function get() {
|
||||
if (!json || process.env.NODE_ENV !== 'production') {
|
||||
json = get_sections();
|
||||
}
|
||||
|
||||
send(res, 200, json);
|
||||
return {
|
||||
body: json
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,18 +1,22 @@
|
||||
import send from '@polka/send';
|
||||
import { get_examples } from './_examples.js';
|
||||
|
||||
let cached;
|
||||
|
||||
export function get(req, res) {
|
||||
try {
|
||||
export function get() {
|
||||
if (!cached || process.env.NODE_ENV !== 'production') {
|
||||
cached = get_examples().filter(section => section.title);
|
||||
}
|
||||
|
||||
send(res, 200, cached);
|
||||
} catch (e) {
|
||||
send(res, e.status || 500, {
|
||||
try {
|
||||
return {
|
||||
body: cached
|
||||
};
|
||||
} catch(err) {
|
||||
return {
|
||||
status: e.status || 500,
|
||||
body: {
|
||||
message: e.message
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +1,31 @@
|
||||
import send from '@polka/send';
|
||||
import body from './_utils/body.js';
|
||||
import { query } from '../../utils/db';
|
||||
|
||||
export async function post(req, res) {
|
||||
const { user } = req;
|
||||
export async function post({ locals, body }) {
|
||||
const { user } = locals;
|
||||
if (!user) return; // response already sent
|
||||
|
||||
try {
|
||||
const { name, files } = await body(req);
|
||||
const { name, files } = body;
|
||||
|
||||
const [row] = await query(`
|
||||
insert into gists(user_id, name, files)
|
||||
values ($1, $2, $3) returning *`, [user.id, name, JSON.stringify(files)]);
|
||||
|
||||
send(res, 201, {
|
||||
return {
|
||||
status: 201,
|
||||
body: {
|
||||
uid: row.uid.replace(/-/g, ''),
|
||||
name: row.name,
|
||||
files: row.files,
|
||||
owner: user.uid,
|
||||
});
|
||||
}
|
||||
};
|
||||
} catch (err) {
|
||||
send(res, 500, {
|
||||
return {
|
||||
status: 500,
|
||||
body: {
|
||||
error: err.message
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,22 @@
|
||||
<script context="module">
|
||||
export function preload({ query }) {
|
||||
export function load({ page: { query }}) {
|
||||
const { gist, example, version } = query;
|
||||
|
||||
// redirect to v2 REPL if appropriate
|
||||
if (/^[^>]?[12]/.test(version)) {
|
||||
const q = Object.keys(query).map(key => `${key}=${query[key]}`).join('&');
|
||||
return this.redirect(302, `https://v2.svelte.dev/repl?${q}`);
|
||||
return {
|
||||
status: 302,
|
||||
redirect: `https://v2.svelte.dev/repl?${q}`
|
||||
};
|
||||
}
|
||||
|
||||
const id = gist || example || 'hello-world';
|
||||
const q = version ? `?version=${version}` : ``;
|
||||
|
||||
this.redirect(301, `repl/${id}${q}`);
|
||||
return {
|
||||
status: 301,
|
||||
redirect: `/repl/${id}${q}`
|
||||
};
|
||||
}
|
||||
</script>
|
||||
@ -1,17 +0,0 @@
|
||||
import { createReadStream } from 'fs';
|
||||
|
||||
export function get(req, res) {
|
||||
const path = req.params.file.join('/');
|
||||
if (process.env.NODE_ENV !== 'development' || ('/' + path).includes('/.')) {
|
||||
res.writeHead(403);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
createReadStream('../' + path)
|
||||
.on('error', () => {
|
||||
res.writeHead(403);
|
||||
res.end();
|
||||
})
|
||||
.pipe(res);
|
||||
res.writeHead(200, { 'Content-Type': 'text/javascript' });
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
export function get({ params: { path } }) {
|
||||
if (process.env.NODE_ENV !== 'development' || ('/' + path).includes('/.')) {
|
||||
return { status: 403 };
|
||||
}
|
||||
return {
|
||||
headers: { 'Content-Type': 'text/javascript' },
|
||||
body: readFileSync('../' + path)
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
<script context="module">
|
||||
export async function load({ fetch }) {
|
||||
const sections = await fetch(`/tutorial.json`).then(r => r.json());
|
||||
return {
|
||||
props: {
|
||||
sections
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { setContext } from 'svelte';
|
||||
|
||||
export let sections;
|
||||
setContext('tutorial', { sections });
|
||||
</script>
|
||||
|
||||
<slot></slot>
|
||||
@ -1,15 +0,0 @@
|
||||
<script context="module">
|
||||
export async function preload() {
|
||||
const sections = await this.fetch(`tutorial.json`).then(r => r.json());
|
||||
return { sections };
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { setContext } from 'svelte';
|
||||
|
||||
export let sections;
|
||||
setContext('tutorial', { sections });
|
||||
</script>
|
||||
|
||||
<slot></slot>
|
||||
@ -1,5 +1,8 @@
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
this.redirect(301, 'tutorial/basics');
|
||||
export function load() {
|
||||
return {
|
||||
status: 301,
|
||||
redirect: '/tutorial/basics'
|
||||
};
|
||||
}
|
||||
</script>
|
||||
@ -1,20 +1,23 @@
|
||||
export function get(req, res) {
|
||||
export async function get(req) {
|
||||
let { min = '0', max = '100' } = req.query;
|
||||
min = +min;
|
||||
max = +max;
|
||||
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
|
||||
// simulate a long delay
|
||||
setTimeout(() => {
|
||||
await new Promise((res) => setTimeout(res, 1000));
|
||||
|
||||
// fail sometimes
|
||||
if (Math.random() < 0.333) {
|
||||
res.statusCode = 400;
|
||||
res.end(`Failed to generate random number. Please try again`);
|
||||
return;
|
||||
return {
|
||||
status: 400,
|
||||
headers: { 'Access-Control-Allow-Origin': '*' },
|
||||
body: `Failed to generate random number. Please try again`
|
||||
};
|
||||
}
|
||||
|
||||
const num = min + Math.round(Math.random() * (max - min));
|
||||
res.end(String(num));
|
||||
}, 1000);
|
||||
return {
|
||||
headers: { 'Access-Control-Allow-Origin': '*' },
|
||||
body: String(num)
|
||||
};
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
import polka from 'polka';
|
||||
import send from '@polka/send';
|
||||
import sirv from 'sirv';
|
||||
import * as sapper from '@sapper/server';
|
||||
import { sanitize_user, authenticate } from './utils/auth';
|
||||
|
||||
if (!process.env.PORT) {
|
||||
process.env.PORT = 3000;
|
||||
}
|
||||
|
||||
const { PORT } = process.env;
|
||||
|
||||
const app = polka({
|
||||
onError: (err, req, res) => {
|
||||
const error = err.message || err;
|
||||
const code = err.code || err.status || 500;
|
||||
res.headersSent || send(res, code, { error }, {
|
||||
'content-type': 'text/plain'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (process.env.PGHOST) {
|
||||
app.use(authenticate());
|
||||
}
|
||||
|
||||
app.use(
|
||||
sirv('static', {
|
||||
dev: process.env.NODE_ENV === 'development',
|
||||
setHeaders(res) {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.hasHeader('Cache-Control') || res.setHeader('Cache-Control', 'max-age=600'); // 10min default
|
||||
}
|
||||
}),
|
||||
|
||||
sapper.middleware({
|
||||
session: req => ({
|
||||
user: sanitize_user(req.user)
|
||||
})
|
||||
})
|
||||
);
|
||||
|
||||
app.listen(PORT);
|
||||
@ -1,87 +0,0 @@
|
||||
import { timestamp, files, shell } from '@sapper/service-worker';
|
||||
|
||||
const ASSETS = `cache${timestamp}`;
|
||||
|
||||
// `shell` is an array of all the files generated by Rollup,
|
||||
// `files` is an array of everything in the `static` directory
|
||||
const to_cache = shell.concat(files.filter(file => {
|
||||
const basename = file.split('/').pop();
|
||||
if (basename[0] === '.') return false; // .DS_Store and friends
|
||||
if (basename.endsWith('.mp3')) return false; // TODO others?
|
||||
return true;
|
||||
}));
|
||||
const cached = new Set(to_cache);
|
||||
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil(
|
||||
caches
|
||||
.open(ASSETS)
|
||||
.then(cache => cache.addAll(to_cache))
|
||||
.then(() => {
|
||||
self.skipWaiting();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(
|
||||
caches.keys().then(async keys => {
|
||||
// delete old caches
|
||||
for (const key of keys) {
|
||||
if (key !== ASSETS) await caches.delete(key);
|
||||
}
|
||||
|
||||
self.clients.claim();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
if (event.request.method !== 'GET' || event.request.headers.has('range')) return;
|
||||
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
// don't try to handle e.g. data: URIs
|
||||
if (!url.protocol.startsWith('http')) return;
|
||||
|
||||
// ignore dev server requests
|
||||
if (url.hostname === self.location.hostname && url.port !== self.location.port) return;
|
||||
|
||||
// always serve static files and Rollup-generated assets from cache
|
||||
if (url.host === self.location.host && cached.has(url.pathname)) {
|
||||
event.respondWith(caches.match(event.request));
|
||||
return;
|
||||
}
|
||||
|
||||
// for pages, you might want to serve a shell `index.html` file,
|
||||
// which Sapper has generated for you. It's not right for every
|
||||
// app, but if it's right for yours then uncomment this section
|
||||
/*
|
||||
if (url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) {
|
||||
event.respondWith(caches.match('/index.html'));
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
if (event.request.cache === 'only-if-cached') return;
|
||||
|
||||
// for everything else, try the network first, falling back to
|
||||
// cache if the user is offline. (If the pages never change, you
|
||||
// might prefer a cache-first approach to a network-first one.)
|
||||
event.respondWith(
|
||||
caches
|
||||
.open(`offline${timestamp}`)
|
||||
.then(async cache => {
|
||||
try {
|
||||
const response = await fetch(event.request);
|
||||
cache.put(event.request, response.clone());
|
||||
return response;
|
||||
} catch (err) {
|
||||
const response = await cache.match(event.request);
|
||||
if (response) return response;
|
||||
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
@ -1,40 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang='en' class="theme-default typo-default">
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
<meta name='theme-color' content='#ff3e00'>
|
||||
|
||||
%sapper.base%
|
||||
|
||||
<link href=global.css rel=stylesheet>
|
||||
<link href=prism.css rel=stylesheet>
|
||||
<link rel='manifest' href='manifest.json'>
|
||||
<link rel='icon' type='image/png' href='favicon.png'>
|
||||
|
||||
<meta name='twitter:card' content='summary_large_image'>
|
||||
<meta name='twitter:site' content='@sveltejs'>
|
||||
<meta name='twitter:creator' content='@sveltejs'>
|
||||
<meta name='twitter:image' content='https://svelte.dev/images/twitter-card.png'>
|
||||
<meta name='og:image' content='https://svelte.dev/images/twitter-card.png'>
|
||||
|
||||
<!-- Sapper generates a <style> tag containing critical CSS
|
||||
for the current page. CSS for the rest of the app is
|
||||
lazily loaded when it precaches secondary pages -->
|
||||
%sapper.styles%
|
||||
|
||||
<!-- This contains the contents of the <svelte:head> component, if
|
||||
the current page has one -->
|
||||
%sapper.head%
|
||||
</head>
|
||||
<body>
|
||||
<!-- The application will be rendered inside this element,
|
||||
because `app/client.js` references it -->
|
||||
<div id='sapper'>%sapper.html%</div>
|
||||
|
||||
<!-- Sapper creates a <script> tag containing `app/client.js`
|
||||
and anything else it needs to hydrate the app and
|
||||
initialise the router -->
|
||||
%sapper.scripts%
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,36 @@
|
||||
import adapter from '@sveltejs/adapter-node';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
export default {
|
||||
kit: {
|
||||
adapter: adapter(),
|
||||
target: '#svelte',
|
||||
prerender: {
|
||||
enabled: false
|
||||
},
|
||||
vite: () => ({
|
||||
optimizeDeps: {
|
||||
include: [
|
||||
'codemirror',
|
||||
'codemirror/mode/javascript/javascript.js',
|
||||
'codemirror/mode/handlebars/handlebars.js',
|
||||
'codemirror/mode/htmlmixed/htmlmixed.js',
|
||||
'codemirror/mode/xml/xml.js',
|
||||
'codemirror/mode/css/css.js',
|
||||
'codemirror/mode/markdown/markdown.js',
|
||||
'codemirror/addon/edit/closebrackets.js',
|
||||
'codemirror/addon/edit/closetag.js',
|
||||
'codemirror/addon/edit/continuelist.js',
|
||||
'codemirror/addon/comment/comment.js',
|
||||
'codemirror/addon/fold/foldcode.js',
|
||||
'codemirror/addon/fold/foldgutter.js',
|
||||
'codemirror/addon/fold/brace-fold.js',
|
||||
'codemirror/addon/fold/xml-fold.js',
|
||||
'codemirror/addon/fold/indent-fold.js',
|
||||
'codemirror/addon/fold/markdown-fold.js',
|
||||
'codemirror/addon/fold/comment-fold.js'
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue