Skip to content

Instantly share code, notes, and snippets.


sooop/blog.html Secret

Last active Jan 16, 2018
What would you like to do?
single page blog with LiveScript + Mithril
<!doctype html>
<script src=""></script>
<script src=""></script>
<script src="./" type="text/ls"></script>
<div id="main">loading</div>
class Post
(args) ->
@title = args?.title || ''
@content = args?.content || ''
@timestamp = args?.timestamp || new Date!get-time!
storage = do
save: (post) !-> local-storage.set-item post.timestamp, JSON.stringify post
load: (key) -> new Post JSON.parse local-storage.get-item key
writer = do
oninit: (vnode) ->
vnode.state = if k = m.route.param \key then post: storage.load k else post: new Post!
view: (vnode) ->
m \.writer,
* \title
m \input,
oninput: m.with-attr \value, !~> = it
m \br
m \textarea, do
onkeyup: m.with-attr \value, !~> = it
m \br
m \button, do
onclick: !~>
m.route.set \/
, \save
lister = do
view: (vnode) ->
m \.lister,
* m \ul, [0 til local-storage.length].map (i) ->
k = local-storage.key i
t = storage.load k .title
m \li, m "a", {href:"/view/#k", oncreate:}, t
m \button, {onclick: !-> m.route.set \/edit/_}, \write
viewer = do
oninit: (vn) ->
if k = m.route.param \key then = storage.load
else m.route.set \/add/new
view: (vn) ->
post =
m \.wrapper,
* m \h1, post.title
m \.content post.content
m \button {onclick: !~> m.route.set "/edit/#{}"}, \edit
m \button {onclick: !-> m.route.set \/}, \list
m.route document.body, \/, do
\/ : lister
'/edit/:key' : writer
'/view/:key' : viewer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment