Commit d679c71d authored by ransome1's avatar ransome1
Browse files

Added page title POC

parent 7d2497fe
{
"name": "sleek",
"productName": "sleek",
"version": "1.2.1",
"version": "1.2.2-rc.1",
"description": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"synopsis": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"category": "ProjectManagement",
......@@ -19,7 +19,7 @@
"main": "src/main.js",
"buildResources": "src",
"build": {
"buildVersion": "18",
"buildVersion": "19",
"files": [
"!flatpak-node${/*}",
"!snap${/*}",
......
......@@ -12294,12 +12294,15 @@ input.is-medium.input {
width: auto;
cursor: pointer;
color: #5a5a5a;
/*a {
font-size: 1.1em;
font-family: FreeSansBold;
height: auto;
padding: 0.15em 0.5em;
}*/
}
#todoTable .cell.text a {
font-size: 1.1em;
font-family: FreeSansBold;
height: auto;
padding: 0.15em 0.5em;
#todoTable .cell.text span.linkText {
color: hsl(217deg, 71%, 53%);
}
#todoTable .cell.text a.button.priority {
font-size: 0.9em;
......
This diff is collapsed.
......@@ -503,6 +503,22 @@
</td>
</tr>
</table>
<table id="getPageTitlesRow" class="settings">
<tr>
<th colspan="100%" id="getPageTitlesHeadline">Replace links with website titles</th>
</tr>
<tr>
<td id="getPageTitlesBody">Description text</td>
<td>
<span class="toggle">
<label class="switch" for="getPageTitles">
<input type="checkbox" id="getPageTitles" class="toggle" tabindex="0">
<span class="slider round"></span>
</label>
</span>
</td>
</tr>
</table>
<table class="settings">
<tr>
<th colspan="100%" id="zoomHeadline"></th>
......
......@@ -24,12 +24,26 @@ marked.setOptions({
xhtml: false,
baseUrl: "https://"
});
const renderer = {
link(href, title, text) {
return `${text} <a href="${href}" target="_blank"><i class="fas fa-external-link-alt"></i></a>`;
}
};
marked.use({ renderer });
// const renderer = {
// link(href, title, text) {
// return `${text} <a href="${href}" target="_blank"><i class="fas fa-external-link-alt"></i></a>`;
// }
// };
// // Override function
// const walkTokens = (token) => {
// if(token.type !== "link") return false;
// console.log(token.text)
// //return `${token.text} <a href="${token.href}" target="_blank"><i class="fas fa-external-link-alt"></i></a>`;
// // link(href, text) {
// // console.log(href)
// // //temp(href);
// // return `${text} <a href="${href}" target="_blank"><i class="fas fa-external-link-alt"></i></a>`;
// // }
// };
// marked.use({ renderer, walkTokens });
// TODO: check if this still works
export function jumpToItem(item) {
......
......@@ -37,6 +37,7 @@ const todoTableBodyCellTextTemplate = document.createElement("div");
const todoTableBodyRowTemplate = document.createElement("div");
const todoTableWrapper = document.getElementById("todoTableWrapper");
let
linkId,
clusterCounter = 0,
clusterSize = Math.ceil(window.innerHeight/32), // 32 being the pixel height of one todo in compact mode
clusterThreshold = clusterSize;
......@@ -72,6 +73,18 @@ todoTableWrapper.onscroll = function(event) {
}
}
// receives a page title and if found replaces the link with it
function getAndsetPageTitle(linkId, href) {
const pageBody = fetch(href);
pageBody.then(response => response.text()).then(async data => {
const regExp = new RegExp("<title[^>]*>(.*?)</title>");
const pageTitle = regExp.exec(data);
const linkElement = await document.getElementById("linkId" + linkId);
if(!linkElement || !pageTitle) return false;
linkElement.innerHTML = pageTitle[1];
})
}
async function generateTodoTxtObjects(fileContent) {
try {
......@@ -370,8 +383,20 @@ function generateTableRow(todo) {
// adds priority to the text cell
if(todo.priority && (sortBy !== "priority" || userData.sortByFile)) todoTableBodyCellText.innerHTML = `<a class="priority button ${todo.priority}">${todo.priority}</a>`;
const renderer = {
link(href, title, text) {
const linkId = Math.random().toString(36).slice(2);
if(userData.getPageTitles) getAndsetPageTitle(linkId, text);
return `<span id="linkId${linkId}" class="linkText">${text}</span> <a href="${href}" target="_blank"><i class="fas fa-external-link-alt"></i></a>`;
}
};
marked.use({ renderer });
// parse text string through markdown parser
todoTableBodyCellText.innerHTML += "<span class=\"text\">" + marked.parseInline(todo.text) + "</span>";
todoTableBodyCellText.innerHTML += "<span class=\"text\">" + marked.parse(todo.text) + "</span>";
// replace line feed character with a space
todoTableBodyCellText.innerHTML = todoTableBodyCellText.innerHTML.replaceAll(String.fromCharCode(16)," ");
......
......@@ -335,6 +335,7 @@ function getUserData() {
if(typeof userData.data.language != "string") userData.data.language = app.getLocale().substr(0,2);
if(typeof userData.data.autoUpdate != "boolean") userData.data.autoUpdate = false;
if(typeof userData.data.theme != "string") userData.set("theme", "system");
if(typeof userData.data.getPageTitles != "boolean") userData.data.getPageTitles = true;
//TODO remove this after 1.1.7 has been fully distributed
const indexOfDueString = userData.data.sortBy.indexOf("dueString");
......
......@@ -103,11 +103,14 @@
width: auto;
cursor: pointer;
color: $dark-grey;
a {
/*a {
font-size: 1.1em;
font-family: FreeSansBold;
height: auto;
padding: 0.15em 0.5em;
}*/
span.linkText {
color: $has-text-link;
}
a.button.priority {
font-size: 0.9em;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment