first beta

This commit is contained in:
Bachir Soussi Chiadmi
2017-05-02 12:17:13 +02:00
parent 4d237e7b5c
commit ec7ad39a11
3 changed files with 75 additions and 21 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
<footer> <footer>
<p>&copy; {{ now.Year }} <a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a></p> <p>&copy; {{ now.Year }} <a href="/">{{ .Site.Title }}</a></p>
</footer> </footer>
<script src="{{ .Site.BaseURL }}main.js" charset="utf-8"></script> <script src="{{ .Site.BaseURL }}main.js" charset="utf-8"></script>
+34 -10
View File
@@ -14,13 +14,14 @@ require('./fonts/opensans/opensans.css');
var m = require('mithril'); var m = require('mithril');
console.log("DataItems", DataItems); // console.log("DataItems", DataItems);
var DataItemsBySlug = {}; var DataItemsBySlug = {};
for (item of DataItems) { for (item in DataItems) {
DataItemsBySlug[item.slug] = item; // console.log(item);
DataItemsBySlug[DataItems[item].slug] = DataItems[item];
} }
console.log("DataItemsBySlug", DataItemsBySlug); // console.log("DataItemsBySlug", DataItemsBySlug);
// __ _ __ // __ _ __
// / / (_)___ / /__ // / / (_)___ / /__
@@ -31,12 +32,21 @@ var _Link = {
targetslug:"", targetslug:"",
opened:false, opened:false,
oninit: function(vn){ oninit: function(vn){
// console.log("vn.attrs", vn.attrs);
vn.state.targetslug = vn.attrs.href.replace(/^.*\/(.+)$/, "$1").replace(/^(.+)\/$/, "$1"); vn.state.targetslug = vn.attrs.href.replace(/^.*\/(.+)$/, "$1").replace(/^(.+)\/$/, "$1");
}, },
view: function(vn){ view: function(vn){
if(vn.state.opened){ if(vn.state.opened){
// return m('div', "Hello "+vn.state.targetslug); // return m('div', "Hello "+vn.state.targetslug);
return m(_Item, DataItemsBySlug[vn.state.targetslug]); // console.log('vn.state.targetslug', vn.state);
return m('div', {'class':'opened-link'},
[
m('span', {'class':"link text"}, vn.children),
m(_Item, DataItemsBySlug[vn.state.targetslug])
]
);
}else{ }else{
return m('a', { return m('a', {
'class':'link', 'class':'link',
@@ -64,6 +74,7 @@ var _Text = {
// initiaize text childNodes array // initiaize text childNodes array
vn.state.textchilds = []; vn.state.textchilds = [];
// parse html string to virtual dom // parse html string to virtual dom
// console.log('vn.attrs.text',vn.attrs.text);
var textdom = new DOMParser().parseFromString(vn.attrs.text, "text/html"); var textdom = new DOMParser().parseFromString(vn.attrs.text, "text/html");
// get the text nodes (avoid html document extra) // get the text nodes (avoid html document extra)
var childs = textdom.getElementsByTagName('body')[0].childNodes; var childs = textdom.getElementsByTagName('body')[0].childNodes;
@@ -81,18 +92,21 @@ var _Text = {
if(typeof childs[i].childNodes[j].localName != "undefined"){ if(typeof childs[i].childNodes[j].localName != "undefined"){
switch (childs[i].childNodes[j].localName) { switch (childs[i].childNodes[j].localName) {
case 'a': case 'a':
// console.log('childs[i].childNodes[j]', childs[i].childNodes[j]);
p.childs.push({ p.childs.push({
tag:'a', tag:'a',
href:childs[i].childNodes[j].href, href:childs[i].childNodes[j].attributes.href.value,
text:childs[i].childNodes[j].innerHTML text:childs[i].childNodes[j].innerHTML
}); });
break; break;
} }
}else{ }else{
// if textnode // if textnode
// console.log(childs[i].childNodes[j]);
// console.log("["+childs[i].childNodes[j].textContent+"]");
p.childs.push({ p.childs.push({
tag:'#text', tag:'#text',
text:childs[i].childNodes[j].data text:childs[i].childNodes[j].textContent //+ (childs[i].childNodes[j].nextSibling ? " " : "")
}); });
} }
} }
@@ -108,6 +122,7 @@ var _Text = {
vn.state.textchilds.map(function(p,i){ vn.state.textchilds.map(function(p,i){
// create paragraph and loop through text and link nodes // create paragraph and loop through text and link nodes
return m('div', {'class':'paragraph'}, p.childs.map(function(c,j) { return m('div', {'class':'paragraph'}, p.childs.map(function(c,j) {
console.log('c',c);
// return p.childs.map(function(c,j) { // return p.childs.map(function(c,j) {
// create text and link node // create text and link node
switch (c.tag) { switch (c.tag) {
@@ -118,13 +133,14 @@ var _Text = {
}, c.text); }, c.text);
break; break;
case '#text': case '#text':
// console.log("["+c.text+"]");
return m.trust(c.text); return m.trust(c.text);
break; break;
} }
}) // /map }) // /map
) // /m.div.paragraph ); // /m.div.paragraph
}) // /map }) // /map
) // /m.div.text ); // /m.div.text
} // view: } // view:
} }
@@ -134,7 +150,15 @@ var _Text = {
// _/ // /_/ __/ / / / / / // _/ // /_/ __/ / / / / /
// /___/\__/\___/_/ /_/ /_/ // /___/\__/\___/_/ /_/ /_/
var _Item = { var _Item = {
slug:null,
part:null,
type:null,
active:0, active:0,
oninit: function(vn){
// console.log('vn.attrs', vn.attrs);
vn.state.slug = vn.attrs.slug;
vn.state.part = vn.state.slug.match(/^(\d)(.+)/)[1];
},
view: function(vn){ view: function(vn){
return m("section", { return m("section", {
'id':vn.attrs.slug, 'id':vn.attrs.slug,
@@ -147,7 +171,7 @@ var _Item = {
onclick: function(e){ onclick: function(e){
vn.state.active = vn.state.active ? 0 : 1; vn.state.active = vn.state.active ? 0 : 1;
} }
}, vn.attrs.title), }, "Part "+vn.state.part+" : "+vn.attrs.title),
// create text node // create text node
m(_Text, {'text':vn.attrs.text, 'slug':vn.attrs.slug}) m(_Text, {'text':vn.attrs.text, 'slug':vn.attrs.slug})
] ]
+40 -10
View File
@@ -5,25 +5,38 @@
// @Last modified time: 18-04-2017 // @Last modified time: 18-04-2017
// @License: GPL-V3 // @License: GPL-V3
$fs:16px;
@mixin base_font{
font-family: 'amiri', sans-serif;
font-size: 16px;
font-kerning: auto;
line-height: 1.4;
}
html, body{ html, body{
font-size: 16px; @include base_font;
font-family: 'amiri', sans-serif;
position: relative; position: relative;
margin:0;
padding:0;
} }
#app{ #app{
position: relative; position: relative;
text-align: center;
margin: 0 auto;
} }
main#content{ main#content{
display:inline-block; display:inline-block;
margin: 0 auto; text-align: left;
} }
section.item{ section.item{
width:350px; width:450px;
margin: 1em 0; margin: 1em 0;
overflow-x: visible;
@include base_font;
// max-height:14px; // max-height:14px;
// overflow: hidden; // overflow: hidden;
// transition: max-height 0.5s ease-in-out; // transition: max-height 0.5s ease-in-out;
@@ -33,15 +46,32 @@ section.item{
h1{ h1{
font-size: 0.750em; font-size: 0.750em;
font-weight: 300;
margin: 0; margin: 0;
cursor:pointer; cursor:pointer;
} }
div.text div.paragraph{ div.text{
margin-bottom: 1em; font-size: 1.3em;
} div.paragraph{
div.text section.item{ margin-bottom: 1em;
padding-left:2em;
border-left: 1px solid #999; div.opened-link{
display:inline;
}
a.link, span.link.text{
font-weight: 600;
text-decoration: none;
color: inherit;
}
span.link.text:after{
content:':'
}
section.item{
padding-left:2em;
border-left: 1px solid #999;
}
}
} }
} }