Commit 7bf1fd62 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Merge branch 'svelte-3' into 'master'

Migrate to Svelte 3 and use Smelte

See merge request eraviart/vitrine!1
parents 12f3777a 1cf0158a
"presets": [
"plugins": [
"legacy": true
"proposal": "minimal"
"env": {
"node": true
"globals": {
"Promise": true,
"Set": true
"parser": "babel-eslint",
"plugins": [
"rules": {
"comma-dangle": ["error", "always-multiline"],
"extends": "eslint:recommended",
"max-len": ["error", {"code": 120, "ignoreRegExpLiterals": true, "ignoreUrls": true, "tabWidth": 2}],
"no-undef": "error",
"no-unused-expressions": "error",
"no-unused-vars": "error",
"no-use-before-define": ["error", "nofunc"],
"quotes": ["error", "double", "avoid-escape"],
"semi": ["error", "never"]
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
"plugins": [
"overrides": [
files: ['**/*.svelte'],
processor: 'svelte3/svelte3'
"rules": {
"semi": ["error", "never"],
"quotes": ["error", "double", "avoid-escape"],
\ No newline at end of file
image: node:10
- npm ci
stage: test
- branches
- master
- svelte-3
# Cf
- NODE_ENV=production npm run export -- --basepath $VITRINE_BASE_PATH
stage: deploy
- master
- svelte-3
# Cf
- NODE_ENV=production npm run export -- --basepath $VITRINE_BASE_PATH
- mv __sapper__/export/vitrine/ public/
- public/
"eslint.autoFixOnSave": true,
"eslint.validate": [
"language": "svelte",
"autoFix": true
\ No newline at end of file
# Vitrine
_Web site displaying pages & data retrieved dynamically from other sites_
* Xavier Arques <>
* François Bouchet <>
* Emmanuel Raviart <>
Copyright (C) 2018 Xavier Arques, François Bouchet, Paula Forteza & Emmanuel Raviart
> Vitrine is free software; you can redistribute it and/or modify
> it under the terms of the GNU Affero General Public License as
> published by the Free Software Foundation, either version 3 of the
> License, or (at your option) any later version.
> Vitrine is distributed in the hope that it will be useful,
> but WITHOUT ANY WARRANTY; without even the implied warranty of
> GNU Affero General Public License for more details.
> You should have received a copy of the GNU Affero General Public License
> along with this program. If not, see <>.
# Vitrine
# sapper-template
_Web site displaying pages & data retrieved dynamically from other sites_
The default [Sapper]( template, available for Rollup and webpack.
![Screenshot of a web site based on Vitrine](
_Vitrine_ is an application that generates dynamically the landing pages of a web site using documents & data retrieved from other sites (using their APIs).
## Getting started
It can currently use pages from:
* [Discourse]( forums
* [GitLab]( projects & groups
It can be used as the home page for a hackathon, to display the projects, the datasets, the participants, etc.
### Using `degit`
_Vitrine_ started as a clone of [Hackdash](, but instead of having its own back-office, it used Discourse and benefits from it power and versatility.
[`degit`]( is a scaffolding tool that lets you create a directory from a branch in a repository. Use either the `rollup` or `webpack` branch in `sapper-template`:
Usages examples:
# for Rollup
npx degit "sveltejs/sapper-template#rollup" my-app
# for webpack
npx degit "sveltejs/sapper-template#webpack" my-app
* [#dataFin hackathon](
* [bureau ouvert de la députée Paula Forteza](
_Vitrine_ is free and open source software.
### Using GitHub templates
* [software repository](
* [GNU Affero General Public License version 3 or greater](
Alternatively, you can use GitHub's template feature with the [sapper-template-rollup]( or [sapper-template-webpack]( repositories.
## Installation & Configuration
git clone
cd vitrine/
npm install
### Running the project
## Customization
However you get the code, you can install dependencies and run the project in development mode with:
To customize Vitrine, edit `site/index.js`. Then validate it and generate `site/site.json` by running:
node generate-site.js site/
cd my-app
npm install # or yarn
npm run dev
### Development
Open up [localhost:3000](http://localhost:3000) and start clicking around.
npm run dev
Consult []( for help getting started.
## Structure
Sapper expects to find two directories in the root of your project — `src` and `static`.
### src
The [src](src) directory contains the entry points for your app — `client.js`, `server.js` and (optionally) a `service-worker.js` — along with a `template.html` file and a `routes` directory.
#### src/routes
This is the heart of your Sapper app. There are two kinds of routes — *pages*, and *server routes*.
**Pages** are Svelte components written in `.svelte` files. When a user first visits the application, they will be served a server-rendered version of the route in question, plus some JavaScript that 'hydrates' the page and initialises a client-side router. From that point forward, navigating to other pages is handled entirely on the client for a fast, app-like feel. (Sapper will preload and cache the code for these subsequent pages, so that navigation is instantaneous.)
**Server routes** are modules written in `.js` files, that export functions corresponding to HTTP methods. Each function receives Express `request` and `response` objects as arguments, plus a `next` function. This is useful for creating a JSON API, for example.
There are three simple rules for naming the files that define your routes:
* A file called `src/routes/about.svelte` corresponds to the `/about` route. A file called `src/routes/blog/[slug].svelte` corresponds to the `/blog/:slug` route, in which case `params.slug` is available to the route
* The file `src/routes/index.svelte` (or `src/routes/index.js`) corresponds to the root of your app. `src/routes/about/index.svelte` is treated the same as `src/routes/about.svelte`.
* Files and directories with a leading underscore do *not* create routes. This allows you to colocate helper modules and components with the routes that depend on them — for example you could have a file called `src/routes/_helpers/datetime.js` and it would *not* create a `/_helpers/datetime` route
### static
The [static](static) directory contains any static assets that should be available. These are served using [sirv](
In your [service-worker.js](src/service-worker.js) file, you can import these as `files` from the generated manifest...
import { files } from '@sapper/service-worker';
### Development that you can cache them (though you can choose not to, for example if you don't want to cache very large files).
## Bundler config
Sapper uses Rollup or webpack to provide code-splitting and dynamic imports, as well as compiling your Svelte components. With webpack, it also provides hot module reloading. As long as you don't do anything daft, you can edit the configuration files to add whatever plugins you'd like.
## Production mode and deployment
To start a production version of your app, run `npm run build && npm start`. This will disable live reloading, and activate the appropriate bundler plugins.
You can deploy your application to any environment that supports Node 8 or above. As an example, to deploy to [Now](, run these commands:
npm run build
npm install -g now
## Discourse Configuration
Discourse must be configurated to accept requests coming from another site (ie CORS must be enabled to accept requests coming from Vitrine web site).
## Using external components
When using Svelte components installed from npm, such as [@sveltejs/svelte-virtual-list](, Svelte needs the original component source (rather than any precompiled JavaScript that ships with the component). This allows the component to be rendered server-side, and also keeps your client-side app smaller.
In file `/var/discourse/containers/app.yml`, add line:
Because of that, it's essential that the bundler doesn't treat the package as an *external dependency*. You can either modify the `external` option under `server` in [rollup.config.js](rollup.config.js) or the `externals` option in [webpack.config.js](webpack.config.js), or simply install the package to `devDependencies` rather than `dependencies`, which will cause it to get bundled (and therefore compiled) with your app:
npm install -D @sveltejs/svelte-virtual-list
Then in Discourse admin web page `/admin/site_settings/category/security` fill field **cors origin** with the URL of the Vitrine web site.
## Bugs and feedback
Sapper is in early development, and may have the odd rough edge here and there. Please be vocal over on the [Sapper issue tracker](
# basePath: /vitrine # or use VITRINE_BASE_PATH environment variable
text: Hackathon XYZ
# The following classes are provided by TailwindCSS
# See and next doc sections
# Or use custom classes
classes: text-black tracking-widest font-thin text-lg
color: text-black
- slug: ""
appBarTitle: Home
title: Welcome to hackathon XYZ!
subTitle: Let's do great things all together
callToActionButtonTitle: Register here
- pageSlug: challenges
buttonTitle: See all challenges
limit: 8
- pageSlug: tools
buttonTitle: See all tools
limit: 4
- pageSlug: data
buttonTitle: See all data
limit: 8
- slug: program
appBarTitle: Program
type: discourse
topic: 8 # ID or slug
- slug: challenges
appBarTitle: Challenges
title: Challenges of the hackathon
newItemButtonTitle: Add a new challenge
type: gitlab
group: agdic-hackathon/challenges
- slug: tools
appBarTitle: Tools
title: Tools of the hackathon
type: discourse
category: outils # ID or slug
- slug: data
appBarTitle: Data
title: Data of the hackathon
"baseUrl": "http://localhost:3000",
"video": false
\ No newline at end of file
"name": "Using fixtures to represent data",
"email": "",
"body": "Fixtures are a great way to mock data for responses to routes"
\ No newline at end of file
describe('Sapper template app', () => {
beforeEach(() => {
it('has the correct <h1>', () => {
cy.contains('h1', 'Great success!')
it('navigates to /about', () => {
cy.get('nav a').contains('about').click();
cy.url().should('include', '/about');
it('navigates to /blog', () => {
cy.get('nav a').contains('blog').click();
cy.url().should('include', '/blog');
\ No newline at end of file
// ***********************************************************
// This example plugins/index.js can be used to load plugins
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
// You can read more here:
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
// For more comprehensive examples of custom
// commands please read more here:
// ***********************************************
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
// This is a great place to put global configuration and
// behavior that modifies Cypress.
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
// You can read more here:
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')
require("@babel/polyfill") //Must be at the top of the entry point to application.
This diff is collapsed.
"name": "vitrine",
"description": "Web site displaying pages & data retrieved dynamically from other sites",
"version": "0.4.0",
"version": "0.5.0",
"license": "AGPL-3.0-or-later",
"repository": "",
"scripts": {
"build": "sapper build",
"dev": "sapper dev",
"export": "sapper export",
"start": "node __sapper__/build"
"dev": "nodemon --watch content --ext yml --exec \"./node_modules/.bin/sapper dev\"",
"build": "sapper build --legacy",
"export": "sapper export --legacy",
"start": "node __sapper__/build",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test": "run-p --race dev cy:run"
"dependencies": {
"bootstrap": "^4.1.3",
"command-line-args": "^5.0.2",
"compression": "^1.7.3",
"jquery": "^3.3.1",
"marked": "^0.5.1",
"material-design-icons": "^3.0.1",
"polka": "^0.5.1",
"popper.js": "^1.14.4",
"sirv": "^0.2.2",
"url-resolve": "^1.0.0",
"video.js": "^7.2.4",
"videojs-contrib-hls": "^5.14.1",
"videojs-flash": "^2.1.2"
"compression": "^1.7.1",
"js-yaml": "^3.13.1",
"polka": "next",
"sirv": "^0.4.0"
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.1.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"autoprefixer": "^9.3.1",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.4",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^1.0.1",
"eslint": "^5.8.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-html": "^4.0.6",
"mini-css-extract-plugin": "^0.4.4",
"node-sass": "^4.10.0",
"npm-run-all": "^4.1.2",
"postcss-loader": "^3.0.0",
"precss": "^3.1.2",
"sapper": "^0.24.0",
"sass-loader": "^7.1.0",
"svelte": "^2.15.2",
"svelte-loader": "^2.11.0",
"webpack": "^4.25.1"
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/runtime": "^7.0.0",
"@fullhuman/postcss-purgecss": "^1.3.0",
"@overleaf/o-error": "^2.1.0",
"autoprefixer": "^9.6.1",
"cssnano": "^4.1.10",
"eslint": "^6.5.1",
"eslint-plugin-svelte3": "^2.7.3",
"nodemon": "^1.19.3",
"npm-run-all": "^4.1.5",
"postcss-import": "^12.0.1",
"ramda": "^0.26.1",
"rollup": "^1.12.0",
"rollup-plugin-babel": "^4.0.2",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-postcss": "^2.0.3",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-svelte": "^5.0.1",
"rollup-plugin-terser": "^4.0.4",
"sapper": "^0.27.0",
"smelte": "^0.1.6",
"svelte": "^3.0.0",
"svelte-preprocess": "^3.1.2",
"tailwindcss": "^1.1.2",
"tailwindcss-elevation": "^0.3.3"
\ No newline at end of file
// From
module.exports = (purge = false) => {
return [
purge &&
preset: "default"
purge &&
content: ["./**/*.svelte"],
extractors: [
extractor: content => {
const fromClasses = content.match(/class:[A-Za-z0-9-_]+/g) || []