Add Svelte as a syntax

This commit is contained in:
Kyle Hubert 2020-10-29 14:33:09 -04:00 committed by GitHub
parent 85594956cf
commit 072fb380d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 133 additions and 0 deletions

3
.gitmodules vendored
View File

@ -197,6 +197,9 @@
[submodule "assets/syntaxes/02_Extra/Apache"]
path = assets/syntaxes/02_Extra/Apache
url = https://github.com/colinta/ApacheConf.tmLanguage
[submodule "assets/syntaxes/02_Extra/Svelte"]
path = assets/syntaxes/02_Extra/Svelte
url = https://github.com/corneliusio/svelte-sublime
[submodule "assets/themes/Coldark"]
path = assets/themes/Coldark
url = https://github.com/ArmandPhilippot/coldark-bat.git

View File

@ -13,6 +13,7 @@
## Syntaxes
- Manpage syntax highlighting has been improved, see #1315 (@keith-hall)
- Add Svelte file syntax, see #1285 (@kjmph)
## New themes

1
assets/syntaxes/02_Extra/Svelte vendored Submodule

@ -0,0 +1 @@
Subproject commit bf92f5b7b69c8ea641d6822fd6d12cc2d9341956

View File

@ -0,0 +1,57 @@
<script>
 import { onMount } from 'svelte';
 import List from './List.svelte';
 import Item from './Item.svelte';
 let item;
 let page;
 async function hashchange() {
 // the poor man's router!
 const path = window.location.hash.slice(1);
 if (path.startsWith('/item')) {
 const id = path.slice(6);
 item = await fetch(`https://node-hnapi.herokuapp.com/item/${id}`).then(r => r.json());
 window.scrollTo(0,0);
 } else if (path.startsWith('/top')) {
 page = +path.slice(5);
 item = null;
 } else {
 window.location.hash = '/top/1';
 }
 }
 onMount(hashchange);
</script>
<style>
 main {
 position: relative;
 max-width: 800px;
 margin: 0 auto;
 min-height: 101vh;
 padding: 1em;
 }
 main :global(.meta) {
 color: #999;
 font-size: 12px;
 margin: 0 0 1em 0;
 }
 main :global(a) {
 color: rgb(0,0,150);
 }
</style>
<svelte:window on:hashchange={hashchange}/>
<main>
 {#if item}
 <Item {item} returnTo="#/top/{page}"/>
 {:else if page}
 <List {page}/>
 {/if}
</main>

View File

@ -0,0 +1,57 @@
<script>
import { onMount } from 'svelte';
import List from './List.svelte';
import Item from './Item.svelte';
let item;
let page;
async function hashchange() {
// the poor man's router!
const path = window.location.hash.slice(1);
if (path.startsWith('/item')) {
const id = path.slice(6);
item = await fetch(`https://node-hnapi.herokuapp.com/item/${id}`).then(r => r.json());
window.scrollTo(0,0);
} else if (path.startsWith('/top')) {
page = +path.slice(5);
item = null;
} else {
window.location.hash = '/top/1';
}
}
onMount(hashchange);
</script>
<style>
main {
position: relative;
max-width: 800px;
margin: 0 auto;
min-height: 101vh;
padding: 1em;
}
main :global(.meta) {
color: #999;
font-size: 12px;
margin: 0 0 1em 0;
}
main :global(a) {
color: rgb(0,0,150);
}
</style>
<svelte:window on:hashchange={hashchange}/>
<main>
{#if item}
<Item {item} returnTo="#/top/{page}"/>
{:else if page}
<List {page}/>
{/if}
</main>

View File

@ -0,0 +1,14 @@
The `App.svelte` file has been added from:
https://github.com/sveltejs/svelte/blob/master/site/content/examples/21-miscellaneous/01-hacker-news/App.svelte
Under the following license:
Copyright (c) 2016-20 [these people](https://github.com/sveltejs/svelte/graphs/contributors)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.