Clean theme and improve api
This commit is contained in:
parent
24ef10da65
commit
586e35e390
6 changed files with 95 additions and 81 deletions
|
@ -6,12 +6,12 @@
|
||||||
> bcst -l
|
> bcst -l
|
||||||
>
|
>
|
||||||
Next step, extract the theme resources:
|
Next step, extract the theme resources:
|
||||||
> bcst -e \<your-theme>
|
> bcst -e \<your-theme> > resources.json
|
||||||
|
|
||||||
This, will create a `resources.json` in the current directory. Now, you can customize it to your needs. Then, generate your start page:
|
This, will create a `resources.json` in the current directory. Now, you can customize it to your needs. Then, generate your start page:
|
||||||
> bcst resources.json \<start-page-destination>
|
> bcst -g \<your-theme> resources.json \<start-page-destination>
|
||||||
|
|
||||||
Voilà!
|
And voila!
|
||||||
|
|
||||||
### Submit your own theme
|
### Submit your own theme
|
||||||
TODO
|
TODO
|
||||||
|
|
11
bcst/args.py
11
bcst/args.py
|
@ -1,11 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
args_parser = argparse.ArgumentParser()
|
|
||||||
args_parser.add_argument("resource", nargs="?", help="A JSON resource file.")
|
|
||||||
args_parser.add_argument("destination", nargs="?",help="Start page folder name.")
|
|
||||||
args_parser.add_argument("-l","--list", dest="list",action="store_true", help="List available themes.")
|
|
||||||
args_parser.add_argument("-e","--extract", metavar="theme",dest="extract", help="Extract theme resource.")
|
|
||||||
args = args_parser.parse_args()
|
|
||||||
|
|
41
bcst/bcst
41
bcst/bcst
|
@ -1,18 +1,37 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from bcst.args import args
|
|
||||||
from bcst.resource import Resource
|
|
||||||
from bcst.theme import *
|
from bcst.theme import *
|
||||||
|
|
||||||
if args.list:
|
import argparse
|
||||||
|
|
||||||
|
# if args.list:
|
||||||
|
# for theme in list_themes():
|
||||||
|
# print("- "+theme)
|
||||||
|
# exit(0)
|
||||||
|
# elif args.extract:
|
||||||
|
# t=Theme("default")
|
||||||
|
# t.extract("resources.json")
|
||||||
|
# exit(0)
|
||||||
|
# elif args.resource and args.destination:
|
||||||
|
# t=Theme("default")
|
||||||
|
# t.update_resource(args.resource)
|
||||||
|
# t.deploy(args.destination)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
args_parser = argparse.ArgumentParser()
|
||||||
|
args_parser.add_argument("-g", "--generate", nargs=3,metavar=("theme","resource","destination"), help="Generate a start page using a <theme> with a <resource> into the <destination> folder.")
|
||||||
|
args_parser.add_argument("-l","--list", dest="list",action="store_true", help="List available themes.")
|
||||||
|
args_parser.add_argument("-e","--extract", metavar="theme", help="Extract theme resource.")
|
||||||
|
args = args_parser.parse_args()
|
||||||
|
|
||||||
|
if args.generate :
|
||||||
|
t=Theme(args.generate[0])
|
||||||
|
t.update_resource(args.generate[1])
|
||||||
|
t.generate(args.generate[2])
|
||||||
|
elif args.list:
|
||||||
for theme in list_themes():
|
for theme in list_themes():
|
||||||
print("- "+theme)
|
print("- "+theme)
|
||||||
exit(0)
|
|
||||||
elif args.extract:
|
elif args.extract:
|
||||||
t=Theme("default")
|
t=Theme(args.extract)
|
||||||
t.extract("resources.json")
|
print(t.resource.content)
|
||||||
exit(0)
|
|
||||||
elif args.resource and args.destination:
|
|
||||||
t=Theme("default")
|
|
||||||
t.update_resource(args.resource)
|
|
||||||
t.deploy(args.destination)
|
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
from os import path
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
class Resource:
|
|
||||||
def __init__(self, resource):
|
|
||||||
self.resource=resource
|
|
||||||
# Read data
|
|
||||||
try:
|
|
||||||
with open(resource,'r') as f:
|
|
||||||
self.data=f.read()
|
|
||||||
except IOError:
|
|
||||||
print("Unable to found "+resource)
|
|
||||||
exit(1)
|
|
||||||
# Decode data
|
|
||||||
try:
|
|
||||||
self.json=json.loads(self.data)
|
|
||||||
except:
|
|
||||||
print("Unable to read json from "+resource)
|
|
||||||
exit(1)
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from bcst.resource import Resource
|
|
||||||
from shutil import copytree, ignore_patterns
|
from shutil import copytree, ignore_patterns
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
import os
|
import json
|
||||||
from os import path
|
from os import path, listdir
|
||||||
|
|
||||||
themes_location=path.join(path.dirname(path.abspath(__file__)),"themes")
|
themes_location=path.join(path.dirname(path.abspath(__file__)),"themes")
|
||||||
|
|
||||||
|
|
||||||
def list_themes():
|
def list_themes():
|
||||||
themes=list()
|
themes=list()
|
||||||
for f in os.listdir(themes_location):
|
for f in listdir(themes_location):
|
||||||
if(not(os.path.isfile(os.path.join(themes_location,f)))):
|
if(not(path.isfile(path.join(themes_location,f)))):
|
||||||
themes.append(f)
|
themes.append(f)
|
||||||
return(themes)
|
return(themes)
|
||||||
|
|
||||||
|
@ -24,15 +24,52 @@ def get_theme_path(name):
|
||||||
print("Could not find theme: "+name)
|
print("Could not find theme: "+name)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
class Theme:
|
|
||||||
|
|
||||||
|
class Resource:
|
||||||
|
"""
|
||||||
|
Load a resource file.
|
||||||
|
- path: Contains the resources location
|
||||||
|
- data: Contains the loaded (from json) resource data
|
||||||
|
- content: Contains the plain text data of the resource file
|
||||||
|
"""
|
||||||
|
def __init__(self, resource_path):
|
||||||
|
self.path=resource_path
|
||||||
|
# Read data
|
||||||
|
try:
|
||||||
|
with open(resource_path,'r') as resFile:
|
||||||
|
self.content=resFile.read()
|
||||||
|
except:
|
||||||
|
self.error("unable to read "+resource_path)
|
||||||
|
# Decode data
|
||||||
|
try:
|
||||||
|
self.data=json.loads(self.content)
|
||||||
|
except:
|
||||||
|
self.error("unable to load json from "+resource_path)
|
||||||
|
|
||||||
|
def error(self, msg):
|
||||||
|
"""
|
||||||
|
Raise error and exit.
|
||||||
|
"""
|
||||||
|
print("In Resource ==> "+msg)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
def update_data(self, new_data):
|
||||||
|
"""
|
||||||
|
Update current resource data.
|
||||||
|
"""
|
||||||
|
self.data.update(new_data)
|
||||||
|
|
||||||
|
|
||||||
|
class Theme:
|
||||||
|
"""
|
||||||
|
Load a theme.
|
||||||
|
"""
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.theme_path=get_theme_path(name)
|
self.path=get_theme_path(name)
|
||||||
self.res_path=self.theme_path+"/resources.json"
|
self.resource=Resource(self.path+"/resources.json")
|
||||||
self.data=Resource(self.res_path).json
|
|
||||||
# Read theme
|
# Read theme
|
||||||
try:
|
try:
|
||||||
with open(self.theme_path+"/index.html",'r') as f:
|
with open(self.path+"/index.html",'r') as f:
|
||||||
self.template=Template(f.read())
|
self.template=Template(f.read())
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Unable to found "+resource)
|
print("Unable to found "+resource)
|
||||||
|
@ -40,17 +77,9 @@ class Theme:
|
||||||
|
|
||||||
def update_resource(self,resource_path):
|
def update_resource(self,resource_path):
|
||||||
r=Resource(resource_path)
|
r=Resource(resource_path)
|
||||||
self.data.update(r.json)
|
self.resource.update_data(r.data)
|
||||||
|
|
||||||
|
def generate(self, dest_path):
|
||||||
def extract(self, dest):
|
copytree(self.path, dest_path, dirs_exist_ok=True,ignore=ignore_patterns("*.json","index.html"))
|
||||||
with open(dest, "w") as resFile:
|
|
||||||
resFile.write(self.data.data)
|
|
||||||
|
|
||||||
|
|
||||||
def deploy(self, dest_path):
|
|
||||||
copytree(self.theme_path, dest_path, dirs_exist_ok=True,ignore=ignore_patterns("*.json","index.html"))
|
|
||||||
themes_dir=os.path.split(self.theme_path)[0]
|
|
||||||
theme_dir=os.path.split(self.theme_path)[1]
|
|
||||||
with open(dest_path+"/index.html", "w") as index:
|
with open(dest_path+"/index.html", "w") as index:
|
||||||
index.write(self.template.render(self.data))
|
index.write(self.template.render(self.resource.data))
|
||||||
|
|
|
@ -4,18 +4,18 @@
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
<link rel="stylesheet" href="assets/style.css">
|
<link rel="stylesheet" href="assets/style.css">
|
||||||
<!-- Removed custom title -->
|
<!-- Removed custom title -->
|
||||||
<!-- Meta injected by Custom Start Page for SEO purposes -->
|
<!-- Meta injected by Custom Start Page for SEO purposes -->
|
||||||
<title>{{ title }}</title>
|
<title>{{ title }}</title>
|
||||||
<meta name="description" content="Jazz is a free, open source and customisable start page for your browser, hosted by Custom Start Page.">
|
<meta name="description" content="Jazz is a free, open source and customisable start page for your browser, hosted by Custom Start Page.">
|
||||||
</head><span id="warning-container"><i data-reactroot=""></i></span><link type="text/css" id="dark-mode" rel="stylesheet" href=""><style type="text/css" id="dark-mode-custom-style"></style>
|
</head>
|
||||||
|
<span id="warning-container">
|
||||||
|
<i data-reactroot=""></i>
|
||||||
|
</span>
|
||||||
|
<link type="text/css" id="dark-mode" rel="stylesheet" href="">
|
||||||
|
<style type="text/css" id="dark-mode-custom-style"></style>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
<body>
|
|
||||||
<!--div id="clock"-->
|
|
||||||
<!--span id="date"--><!--/span-->
|
|
||||||
<!--span class="slash"--><!--/span-->
|
|
||||||
<!--span id="time"--><!--/span-->
|
|
||||||
<!--/div-->
|
|
||||||
<main>
|
<main>
|
||||||
{% for key,value in bookmarks.items() %}
|
{% for key,value in bookmarks.items() %}
|
||||||
<section>
|
<section>
|
||||||
|
@ -33,5 +33,5 @@
|
||||||
</main>
|
</main>
|
||||||
<script src="assets/script.js"></script>
|
<script src="assets/script.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Reference in a new issue