Skip to content

Commit

Permalink
basic classless theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Apr 11, 2018
0 parents commit 1564393
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.DS_Store
node_modules
tmp
7 changes: 7 additions & 0 deletions LICENSE
@@ -0,0 +1,7 @@
Copyright (c) 2018 Giovanni P

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.
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@

13 changes: 13 additions & 0 deletions _config.yml
@@ -0,0 +1,13 @@
theme:
commit_sha:
theme_url:
footer: partials/footer.html
aside: partials/aside.html
nav:
- label: Home
url: /
- label: Archives
url: /archives/
date_format: 'MMMM Do YYYY'
show_excerpts: true
read_more: 'Read more...'
55 changes: 55 additions & 0 deletions layout/index.ejs
@@ -0,0 +1,55 @@
<% if (page.title) { %>
<article>
<%- partial('partials/article-header', {showDate: false}) %>
<div><%- page.content %></div>
</article>
<% } %>

<section>
<ul>
<% page.posts.forEach(function (post) { %>
<li>
<article>
<%- partial('partials/article-header', {
page: {
cover: post.cover,
title: post.title,
tags: post.tags,
permalink: post.permalink,
date: post.date
},
showDate: true
}) %>
<% if (theme.show_excerpts && post.excerpt) { %>
<div>
<%- post.excerpt %>
<% if (post.more) { %>
<a href="<%= url_for(post.path) %>"><%= theme.read_more %></a>
<% } %>
</div>
<% } %>
</article>
</li>
<% }) %>
</ul>
</section>
<footer>
<nav>
<ul>
<li>
<a <% if (page.prev) { %>
href="<%= url_for(page.prev_link) %>"
<% } %>>
prev
</a>
</li>
<li>
<a <% if (page.next) { %>
href="<%= url_for(page.next_link) %>"
<% } %>>
next
</a>
</li>
</ul>
</nav>
</footer>
87 changes: 87 additions & 0 deletions layout/layout.ejs
@@ -0,0 +1,87 @@
<!doctype html>
<head>
<meta charset="utf-8">
<meta name="description" content="<%= config.description %>">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=yes">
<title></title>
<% if (theme.commit_sha && theme.theme) { %>
<link rel="stylesheet" href="https://cdn.rawgit.com/fiatjaf/classless/<%= theme.commit_sha %>/themes/<%= theme.theme %>/theme.css">
<% } else if (theme.theme_url) { %>
<link rel="stylesheet" href="<%= theme.theme_url %>">
<% } else { %>
<link rel="stylesheet" id="chosen-theme" href="https://rawgit.com/fiatjaf/classless/master/themes/plain/theme.css">
<script>
let link = document.getElementById('chosen-theme')
let widget = document.createElement('div')
widget.style.position = 'absolute'
widget.style.right = '5px'
widget.style.top = '2px'
widget.style.background = 'beige'
widget.style.color = '#444'
widget.style.zIndex = 99
widget.style.padding = '4px 8px'
widget.innerHTML = `
<label>
<p>No theme was set on <code>theme_config</code>.<br>
Choose a theme from the list to experiment with it:</p>
<select></select>
</label>
`
fetch('https://api.github.com/repos/fiatjaf/classless/contents/themes')
.then(r => r.json())
.then(files => {
document.body.appendChild(widget)
let select = document.querySelector('select')
files
.filter(f => f.type === 'dir')
.forEach(f => {
let option = document.createElement('option')
option.value = f.name
option.innerHTML = f.name
select.appendChild(option)
})
let options = Array.from(select.querySelectorAll('option'))
let chosen = options[parseInt(Math.random() * options.length)]
chosen.selected = true
link.href = link.href.replace(/themes\/[^\/]+/, `themes/${chosen.value}`)
select.addEventListener('change', e => {
let chosen = e.target.value
link.href = link.href.replace(/themes\/[^\/]+/, `themes/${chosen}`)
})
})
.catch(console.log)
</script>
<% } %>
</head>

<body>
<header role="banner">
<a href="<%= url_for('/') %>">
<img src="https://picsum.photos/640/480">
</a>
<h1>
<a href="<%= url_for('/') %>"><%= config.title %></a>
</h1>
<aside>
<p><%= config.description %></p>
</aside>
</header>
<nav>
<ul>
<% theme.nav.forEach(function (item) { %>
<li>
<a href="<%= item.url %>"><%= item.label %></a>
</li>
<% }) %>
</ul>
</nav>
<main>
<%- body %>
</main>
<aside>
<%- partial(theme.aside) %>
</aside>
<footer role="contentinfo">
<%- partial(theme.footer) %>
</footer>
</body>
18 changes: 18 additions & 0 deletions layout/partials/article-header.ejs
@@ -0,0 +1,18 @@
<header>
<% if (page.cover) { %>
<a href="<%= page.permalink %>"><img src="<%= page.cover %>"></a>
<% } %>
<h1><a href="<%= page.permalink %>"><%= page.title %></a></h1>
<aside>
<% if (showDate) { %>
<time datetime="<%= page.date.format('YYY-MM-DD') %>">
<%= page.date.format(theme.date_format) %>
</time>
<% } %>
<ul>
<% (page.tags || []).forEach(function (tag) { %>
<li><a href="<%= url_for(tag.path) %>"><%= tag.name %></a></li>
<% }) %>
</ul>
</aside>
</header>
2 changes: 2 additions & 0 deletions layout/partials/aside.html
@@ -0,0 +1,2 @@
<p>This is an `aside`, a useful place to put information of any kind: metadata about the site author (with or without pictures), brief information about the purposes of the site, a static collection of external links or anything else.</p>
<p>For some Classless themes pictures and data about the author may suit better in the `cover` and `description` site attributes (see `config.toml`), but most of the times that kind of information will fit here better.</p>
2 changes: 2 additions & 0 deletions layout/partials/footer.html
@@ -0,0 +1,2 @@
<p>A default site footer. If you don't know what to place here maybe you should just write your name plus the current year?</p>
<p>If you want to have a sitemap, a contact form or other complex stuff, most Classless themes will also handle it nicely. Or you can take a look at the <code>aside.html</code> partial.</p>
4 changes: 4 additions & 0 deletions layout/post.ejs
@@ -0,0 +1,4 @@
<article>
<%- partial('partials/article-header', {showDate: true}) %>
<div><%- page.content %></div>
</article>
5 changes: 5 additions & 0 deletions package.json
@@ -0,0 +1,5 @@
{
"name": "hexo-theme-classless",
"version": "0.0.1",
"private": true
}

0 comments on commit 1564393

Please sign in to comment.