This commit is contained in:
Cadey Ratio 2020-11-15 15:52:57 -05:00
parent ed50861a3e
commit 863aec0e5b
14 changed files with 110 additions and 93 deletions

View File

@ -6,6 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/png" href="/static/favicon.png"/>
<link rel="icon" href="/static/favicon.ico" type="image/x-icon"/>
<link rel="manifest" href="/static/manifest.json" />
<div id="root"></div>
</head>
<body id="top">
<main>

View File

@ -2,7 +2,7 @@
with pkgs;
let
backend = pkgs.callPackage ./backend { inherit sources pkgs; };
frontend = pkgs.callPackage ./frontend { inherit sources pkgs; };
frontend = pkgs.callPackage ./sina { inherit sources pkgs; };
gruvbox = pkgs.callPackage sources.gruvbox-css { };
in stdenv.mkDerivation {
pname = "mi";

View File

@ -22,6 +22,7 @@ in pkgs.mkShell rec {
elmPackages.elm-format
elmPackages.elm-language-server
elm2nix
nodePackages.uglify-js
# keep this line if you use bash
bashInteractive

2
sina/.gitignore vendored
View File

@ -12,3 +12,5 @@ node_modules
# Desktop Services Store on macOS
.DS_Store
elm.js

View File

@ -1,8 +1,8 @@
{ nixpkgs ? <nixpkgs>
, config ? {}
{ sources ? import ../nix/sources.nix
, pkgs ? import sources.nixpkgs {}
}:
with (import nixpkgs config);
with pkgs;
let
mkDerivation =
@ -18,7 +18,7 @@ let
inherit name src;
buildInputs = [ elmPackages.elm ]
++ lib.optional outputJavaScript nodePackages_10_x.uglify-js;
++ lib.optional outputJavaScript nodePackages.uglify-js;
buildPhase = pkgs.elmPackages.fetchElmDeps {
elmPackages = import srcs;
@ -37,7 +37,7 @@ let
${lib.optionalString outputJavaScript ''
echo "minifying ${elmfile module}"
uglifyjs $out/${module}.${extension} --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' \
| uglifyjs --mangle --output=$out/${module}.min.${extension}
| uglifyjs --mangle --output $out/${module}.min.${extension}
''}
'') targets)}
'';

View File

@ -1,5 +1,10 @@
{
"elm/json" = {
sha256 = "1a107nmm905dih4w4mjjkkpdcjbgaf5qjvr7fl30kkpkckfjjnrw";
version = "1.1.2";
};
"elm/html" = {
sha256 = "1n3gpzmpqqdsldys4ipgyl1zacn0kbpc3g4v3hdpiyfjlgh8bf3k";
version = "1.0.0";
@ -15,21 +20,41 @@
version = "1.0.4";
};
"elm/json" = {
sha256 = "1a107nmm905dih4w4mjjkkpdcjbgaf5qjvr7fl30kkpkckfjjnrw";
version = "1.1.2";
};
"elm/url" = {
sha256 = "0av8x5syid40sgpl5vd7pry2rq0q4pga28b4yykn9gd9v12rs3l4";
version = "1.0.0";
};
"elm/http" = {
sha256 = "008bs76mnp48b4dw8qwjj4fyvzbxvlrl4xpa2qh1gg2kfwyw56v1";
version = "2.0.0";
};
"elm/time" = {
sha256 = "0vch7i86vn0x8b850w1p69vplll1bnbkp8s383z7pinyg94cm2z1";
version = "1.0.0";
};
"rtfeldman/elm-iso8601-date-strings" = {
sha256 = "1fa5sslklldy0dq8bm0zdkb9ni50yxhb09xb6lgk00x55bmza9ik";
version = "1.1.3";
};
"elm/bytes" = {
sha256 = "02ywbf52akvxclpxwj9n04jydajcbsbcbsnjs53yjc5lwck3abwj";
version = "1.0.8";
};
"elm/file" = {
sha256 = "1rljcb41dl97myidyjih2yliyzddkr2m7n74x7gg46rcw4jl0ny8";
version = "1.0.5";
};
"elm/parser" = {
sha256 = "0a3cxrvbm7mwg9ykynhp7vjid58zsw03r63qxipxp3z09qks7512";
version = "1.1.0";
};
"elm/virtual-dom" = {
sha256 = "0q1v5gi4g336bzz1lgwpn5b1639lrn63d8y6k6pimcyismp2i1yg";
version = "1.0.2";

View File

@ -1,22 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="icon" href="%PUBLIC_URL%/favicon.ico">
<title>Elm App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
</body>
</html>

View File

@ -1,13 +1,10 @@
module Main exposing (..)
import Browser
import Html exposing (Html, text, div, h1, img)
import Html exposing (Html, div, h1, img, text)
import Html.Attributes exposing (src)
---- MODEL ----
type alias Model =
{}
@ -17,10 +14,6 @@ init =
( {}, Cmd.none )
---- UPDATE ----
type Msg
= NoOp
@ -30,22 +23,13 @@ update msg model =
( model, Cmd.none )
---- VIEW ----
view : Model -> Html Msg
view model =
div []
[ img [ src "/logo.svg" ] []
, h1 [] [ text "Your Elm App is working!" ]
[ h1 [] [ text "Your Elm App is working!" ]
]
---- PROGRAM ----
main : Program () Model Msg
main =
Browser.element

View File

@ -1,12 +0,0 @@
import './main.css';
import { Elm } from './Main.elm';
import * as serviceWorker from './serviceWorker';
Elm.Main.init({
node: document.getElementById('root')
});
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();

View File

@ -1,26 +0,0 @@
/*
elm-hot creates an additional div wrapper around the app to make HMR possible.
This could break styling in development mode if you are using Elm UI.
More context in the issue:
https://github.com/halfzebra/create-elm-app/issues/320
*/
[data-elm-hot="true"] {
height: inherit;
}
body {
font-family: 'Source Sans Pro', 'Trebuchet MS', 'Lucida Grande', 'Bitstream Vera Sans', 'Helvetica Neue', sans-serif;
margin: 0;
text-align: center;
color: #293c4b;
}
h1 {
font-size: 30px;
}
img {
margin: 20px 0;
max-width: 200px;
}

View File

@ -1 +0,0 @@
../frontend/app.html

7
static/install-sw.js Normal file
View File

@ -0,0 +1,7 @@
if (navigator.serviceWorker.controller) {
console.log("Active service worker found, no need to register");
} else {
navigator.serviceWorker.register("/sw.js").then(function(reg) {
console.log("Service worker has been registered for scope:" + reg.scope);
});
}

View File

@ -1,9 +1,9 @@
{
"short_name": "Elm App",
"name": "Create Elm App Sample",
"short_name": "mi",
"name": "mi_irl",
"icons": [
{
"src": "favicon.ico",
"src": "/static/favicon.png",
"sizes": "192x192",
"type": "image/png"
}

57
static/sw.js Normal file
View File

@ -0,0 +1,57 @@
//This is the service worker with the combined offline experience (Offline page + Offline copy of pages)
//Install stage sets up the offline page in the cache and opens a new cache
self.addEventListener('install', function(event) {
event.waitUntil(preLoad());
});
const cacheName = "cache-xesite-2.0.0";
var preLoad = function(){
console.log('[PWA Builder] Install Event processing');
return caches.open(cacheName).then(function(cache) {
return cache.addAll(['/static/gruvbox.css', '/', '/static/elm.js']);
});
};
self.addEventListener('fetch', function(event) {
if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') {
return;
}
event.respondWith(checkResponse(event.request).catch(function() {
return returnFromCache(event.request);
}));
event.waitUntil(addToCache(event.request));
});
var checkResponse = function(request){
return new Promise(function(fulfill, reject) {
fetch(request).then(function(response){
if(response.status !== 404) {
fulfill(response);
} else {
reject();
}
}, reject);
});
};
var addToCache = function(request){
return caches.open(cacheName).then(function (cache) {
return fetch(request).then(function (response) {
return cache.put(request, response);
});
});
};
var returnFromCache = function(request){
return caches.open(cacheName).then(function (cache) {
return cache.match(request).then(function (matching) {
if(!matching || matching.status == 404) {
return cache.match('offline.html');
} else {
return matching;
}
});
});
};