diff --git a/app.py b/app.py
index c3e8584..2d0d330 100644
--- a/app.py
+++ b/app.py
@@ -4,12 +4,10 @@ from ldap3 import Server, Connection, ALL, MODIFY_REPLACE
from flask import Flask, g, request, session, redirect, url_for, render_template
from flask_simpleldap import LDAP
from flask_bootstrap import Bootstrap
-from readabilipy import simple_json_from_html_string
import os
import sqlite3
import requests
-from requests.api import head
-from utils import clean_articles
+from utils import clean_articles, get_article
app = Flask(__name__)
Bootstrap(app)
@@ -65,7 +63,7 @@ def index():
conn.commit()
conn.close()
- return render_template('list.j2', articles = clean_articles(rows))
+ return render_template('list.j2', articles = rows)
@app.route('/archived')
@@ -81,13 +79,13 @@ def archived():
conn.commit()
conn.close()
- return render_template('list.j2', articles = clean_articles(rows))
+ return render_template('list.j2', articles = rows)
-@app.route('/save')
+@app.route('/bookmarklet')
@ldap.login_required
-def save():
- return render_template('save.j2')
+def bookmarklet():
+ return render_template('bookmarklet.j2')
@app.route('/login', methods=['GET', 'POST'])
@@ -145,16 +143,13 @@ def add_url():
c = conn.cursor()
if url is not None and len(url) > 0:
- headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
- response = requests.get(url, headers=headers)
-
- article = simple_json_from_html_string(response.text, use_readability=True)
+ article, short_domain = get_article(url)
c.execute("SELECT * FROM articles WHERE url=?", (url,))
rows = c.fetchall()
if (len(rows) == 0):
- c.execute("INSERT INTO articles (url, content, title, byline) VALUES (?, ?, ?, ?)", (url, article['content'], article['title'], article['byline']))
+ c.execute("INSERT INTO articles (url, content, title, byline) VALUES (?, ?, ?, ?)", (url, article['content'], article['title'], short_domain))
c.execute("SELECT * FROM articles WHERE url=?", (url,))
rows = c.fetchall()
diff --git a/pocket/readitlater.db b/pocket/readitlater.db
index 2613c23..1597720 100644
Binary files a/pocket/readitlater.db and b/pocket/readitlater.db differ
diff --git a/static/add_modal.js b/static/add_modal.js
new file mode 100644
index 0000000..b13c8ef
--- /dev/null
+++ b/static/add_modal.js
@@ -0,0 +1,37 @@
+function openLinkModal() {
+ $('#addLinkModal').modal('show');
+}
+
+function addUrl() {
+ $("#link-btn").prop("disabled", true);
+
+ url = $('#link-form').val();
+
+ if (url.trim().length === 0) {
+ showError('URL is required');
+ return false;
+ }
+
+ $.ajax({
+ url: '/add',
+ method: 'POST',
+ data: { "url": url },
+ success: function(data) {
+ $('#link-form').val('');
+ $("#link-btn").prop("disabled", false);
+ if (data !== 'Error')
+ window.location.reload();
+ else
+ showError('URL cannot be empty');
+ }
+ });
+}
+
+function showError(error) {
+ $('#error-alert').text(error);
+ $('#error-alert').show();
+}
+
+$('#addLinkModal').on('shown.bs.modal', function () {
+ $('#link-form').trigger('focus');
+});
\ No newline at end of file
diff --git a/static/style.css b/static/style.css
index 416628d..e8208f4 100644
--- a/static/style.css
+++ b/static/style.css
@@ -39,6 +39,14 @@
color: black;
}
+#sidebar div > a {
+ color: rgba(0,0,0,.5);
+}
+
+#sidebar div.active > a {
+ color: black;
+}
+
#content {
width: 100%;
padding: 20px;
@@ -64,6 +72,14 @@
#sidebar ul > li.active > a {
color: white;
}
+
+ #sidebar div > a {
+ color: rgba(255,255,255,.5);
+ }
+
+ #sidebar div.active > a {
+ color: white;
+ }
body {
background-color: #111 !important;
diff --git a/templates/bookmarklet.j2 b/templates/bookmarklet.j2
new file mode 100644
index 0000000..db76cd7
--- /dev/null
+++ b/templates/bookmarklet.j2
@@ -0,0 +1,53 @@
+{% extends "bootstrap/base.html" %}
+{% block title %}Read TI Later{% endblock %}
+
+{% block styles %}
+{{super()}}
+
+{% endblock %}
+
+{% block navbar %}
+
+
Read TI Later
+
+
+
+
+
+{% endblock %}
+
+{% block content %}
+
+
+
+
+
+
+
+
Would you rather save on the go? Try our bookmarklet!
+
+ javascript:(function(){var%20url%20=%20location.href;var%20otherWindow=window.open('about:blank','_blank');otherWindow.opener=null;otherWindow.location='https://read.technicalincompetence.club/add?close=1&url='+encodeURIComponent(url);})();
+
+
+
+
+{% endblock %}
+
+{% block scripts %}
+{{ super() }}
+{% endblock %}
\ No newline at end of file
diff --git a/templates/fragments/add_modal.j2 b/templates/fragments/add_modal.j2
new file mode 100644
index 0000000..b095900
--- /dev/null
+++ b/templates/fragments/add_modal.j2
@@ -0,0 +1,16 @@
+
\ No newline at end of file
diff --git a/templates/fragments/sidebar.j2 b/templates/fragments/sidebar.j2
new file mode 100644
index 0000000..1bf2fca
--- /dev/null
+++ b/templates/fragments/sidebar.j2
@@ -0,0 +1,56 @@
+
+ {% if request.path == url_for('index') %}
+
+ {% else %}
+
+ {% endif %}
+
+
+
+ My List
+
+
+ {% if request.path == url_for('archived') %}
+
+ {% else %}
+
+ {% endif %}
+
+
+ Archived
+
+
+
+ {% if request.path == url_for('bookmarklet') %}
+
+ {% else %}
+
\ No newline at end of file
diff --git a/templates/list.j2 b/templates/list.j2
index 1aa862e..de5d846 100644
--- a/templates/list.j2
+++ b/templates/list.j2
@@ -31,7 +31,7 @@
@@ -42,44 +42,7 @@
@@ -90,7 +53,7 @@
{% for article in articles|reverse %}
+
+{% include "fragments/add_modal.j2" %}
{% endblock %}
{% block scripts %}
{{ super() }}
+
{% endblock %}
\ No newline at end of file
diff --git a/templates/save.j2 b/templates/save.j2
deleted file mode 100644
index a7a7b5c..0000000
--- a/templates/save.j2
+++ /dev/null
@@ -1,148 +0,0 @@
-{% extends "bootstrap/base.html" %}
-{% block title %}Read TI Later{% endblock %}
-
-{% block styles %}
-{{super()}}
-
-{% endblock %}
-
-{% block navbar %}
-
-
Read TI Later
-
-
-
-
-
-{% endblock %}
-
-{% block content %}
-
-
-
-
-
-
-
- This is a danger alert—check it out!
-
-
-
-
-{% endblock %}
-
-{% block scripts %}
-{{ super() }}
-
-{% endblock %}
\ No newline at end of file
diff --git a/utils.py b/utils.py
index 7fb6d1e..fec64a2 100644
--- a/utils.py
+++ b/utils.py
@@ -1,4 +1,6 @@
from urllib.parse import urlparse
+from readabilipy import simple_json_from_html_string
+import requests
def clean_articles(rows):
#article_id, url, title, byline
@@ -9,4 +11,15 @@ def clean_articles(rows):
result = '{uri.netloc}'.format(uri=parsed_uri)
out.append([row[0], row[1], row[2], row[3], result])
- return out
\ No newline at end of file
+ return out
+
+
+def get_article(url):
+ headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
+ response = requests.get(url, headers=headers)
+
+ article = simple_json_from_html_string(response.text, use_readability=True)
+ parsed_uri = urlparse(url)
+ result = '{uri.netloc}'.format(uri=parsed_uri)
+
+ return article, result
\ No newline at end of file