commit 044171405149755ba9fa81694da904d8ae33091c
parent f4bbac11bdeb81ae1a7bbe2a58b7b52231f730f7
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Mon, 22 Jun 2026 18:43:45 +0000
Iens also have title, source, and source URL
Diffstat:
3 files changed, 106 insertions(+), 13 deletions(-)
diff --git a/src/cgi.scm b/src/cgi.scm
@@ -282,7 +282,7 @@ END-OF-CSS
(include "common.scm")
-(unless (= 6 (db-version))
+(unless (= 7 (db-version))
(die "Unexpectad database version"))
@@ -712,7 +712,8 @@ END-OF-CSS
UNION ALL
SELECT -entry.id,(CASE WHEN protected=0 THEN 2 ELSE 3 END),
strftime('%Y.%m.%d %H:%M:%S',ctime,'unixepoch') AS ptime,
- 'Iens','',url,NULL,
+ COALESCE(source,'Untracked Ien'),
+ COALESCE(title,''),url,source_url,
group_concat('#'||name,' '),COALESCE(description,notes)
FROM entry LEFT OUTER JOIN tagrel ON url_id=entry.id
LEFT OUTER JOIN tag ON tag_id=tag.id
@@ -749,7 +750,9 @@ END-OF-CSS
(with-transaction db
(lambda ()
(exec
- (sql db "INSERT INTO entry(url,type,description,notes,ctime,mtime,ptime,protected)
+ (sql db "INSERT INTO entry(url,type,description,notes,
+ title,source,source_url,
+ ctime,mtime,ptime,protected)
SELECT url,
CASE WHEN description IS NULL THEN NULL
WHEN substr(description,1,1)='<' THEN 'html'
diff --git a/src/common.scm b/src/common.scm
@@ -60,6 +60,7 @@
auto INTEGER DEFAULT 0);"
"CREATE TABLE entry (id INTEGER PRIMARY KEY,
url TEXT NOT NULL, type TEXT, description TEXT, notes TEXT,
+ title TEXT, section TEXT, section_url TEXT,
protected INTEGER DEFAULT 0, ptime INTEGER,
ctime INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP,
mtime INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP);"
@@ -189,6 +190,45 @@
"UPDATE selector SET name = text;"
"PRAGMA user_version = 6;")))
+(when (= 6 (db-version))
+ (with-transaction db
+ (lambda ()
+ (for-each
+ (lambda (s) (exec (sql/transient db s)))
+ (list
+ "ALTER TABLE entry ADD COLUMN title TEXT;"
+ "ALTER TABLE entry ADD COLUMN source TEXT;"
+ "ALTER TABLE entry ADD COLUMN source_url TEXT;"
+ "UPDATE entry
+ SET title=rtrim(substr(notes,
+ instr(notes,']')+2,
+ instr(notes,'://')-instr(notes,']')-7),
+ ' '||CHAR(10)),
+ source=substr(notes,
+ instr(notes,'[')+1,
+ instr(notes,']')-instr(notes,'[')-1)
+ WHERE notes GLOB '*ruikBot*';"
+; WHERE notes REGEXP '^[0-9.: <]*[GMN]ruikBot_?> \\[[^]]*\\]';"
+ "UPDATE entry SET source=substr(source,1,instr(source,':')-1)
+ WHERE instr(source,':')>0;"
+ "UPDATE entry SET source=substr(source,1,instr(source,' - ')-1)
+ WHERE instr(source,' - ')>0;"
+ "UPDATE entry
+ SET source_url=substr(description,
+ instr(description,'via ['||source||']('))
+ WHERE instr(description,'via ['||source||'](')>0
+ AND description
+ GLOB '*(via [[]'||source||'[]](*) [Ss]ur #gcuf[fe]ed[f)]?'
+ AND description
+ NOT GLOB '*(via [[]'||source||'[]](*)*) sur #gcufeed)?';"
+; AND description REGEXP '\\(via \\['||source||'\\]\\([^\\)]*\\) ([Ss]ur |via )?#g(cu|uc)f[fe]e?ed[f)]?';"
+ "UPDATE entry
+ SET source_url=substr(source_url,
+ instr(source_url,'(')+1,
+ instr(source_url,')')-instr(source_url,'(')-1)
+ WHERE source_url IS NOT NULL;"
+ "PRAGMA user_version = 7;")))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;
;; Database Utilitities
diff --git a/src/iens.scm b/src/iens.scm
@@ -100,7 +100,7 @@
(include "common.scm")
-(assert (= 6 (db-version)))
+(assert (= 7 (db-version)))
;;;;;;;;;;;;;;;;;;
;; Configuration
@@ -594,16 +594,23 @@
"Append new lines of notes"
(apply add-notes* (time-id-strings args)))
-(define (print-entry-row id url type descr notes protected ptime ctime mtime tags)
+(define (print-entry-row id url type descr notes title source source-url
+ protected ptime ctime mtime tags)
(write-line (conc vt100-entry-header
"#" id (if (zero? protected) "" "*") " - " url
vt100-reset))
- (unless (null? ctime) (write-line (conc "Created " (rfc-3339 ctime))))
- (unless (null? ptime) (write-line (conc "Protected " (rfc-3339 ptime))))
- (unless (null? mtime) (write-line (conc "Modified " (rfc-3339 mtime))))
+ (unless (null? ctime) (write-line (conc "Created: " (rfc-3339 ctime))))
+ (unless (null? ptime) (write-line (conc "Protected: " (rfc-3339 ptime))))
+ (unless (null? mtime) (write-line (conc "Modified: " (rfc-3339 mtime))))
+ (unless (null? title) (write-line (conc "Title: " title)))
+ (if (null? source)
+ (unless (null? source-url)
+ (write-line (conc "Orphan source URL: " source-url)))
+ (write-line (conc "from " source
+ (if (null? source-url) "" (conc " " source-url)))))
(unless (null? descr)
(if (null? type)
- (write-line "Descripiton:")
+ (write-line "Description:")
(write-line (conc "Description (" type "):")))
(write-string descr))
(unless (null? notes)
@@ -683,8 +690,9 @@
(define (print-entry* entry-id)
(query (for-each-row* print-entry-row)
- (sql db "SELECT entry.id,url,type,description,notes,
- protected,ptime,ctime,mtime,group_concat(tag.name,' ')
+ (sql db "SELECT entry.id, url, type, description, notes,
+ title, source, source_url, protected,
+ ptime, ctime, mtime, group_concat(tag.name, ' ')
FROM entry
LEFT OUTER JOIN tagrel ON entry.id=tagrel.url_id
LEFT OUTER JOIN tag ON tag.id=tagrel.tag_id
@@ -708,8 +716,9 @@
(for-each-row* print-entry-row)
((if id sql sql/transient) db
(string-append
- "SELECT entry.id,url,type,description,notes,
- protected,ptime,ctime,mtime,group_concat(tag.name,' ')
+ "SELECT entry.id, url, type, description, notes,
+ title, source, source_url, protected,
+ ptime, ctime, mtime, group_concat(tag.name, ' ')
FROM entry
LEFT OUTER JOIN tagrel ON entry.id=tagrel.url_id
LEFT OUTER JOIN tag ON tag.id=tagrel.tag_id "
@@ -764,6 +773,47 @@
((3) (set-descr* first (car args) (cadr args) (caddr args)))
(else (assert #f "Too many arguments to set-descr " (cons first args)))))
+(define (set-source* mtime entry-id source source-url)
+ (trace `(set-source ,mtime ,entry-id ,source ,source-url))
+ (unless-protected entry-id
+ (exec (sql db "UPDATE entry
+ SET source=?, source_url=COALESCE(?,source_url), mtime=?
+ WHERE id=?;")
+ source source-url mtime entry-id)))
+
+(defcmd (set-source first . args)
+ "[[mtime] entry-id] source [source-URL]" "Sets entry source"
+ (case (length args)
+ ((0) (set-source* (current-seconds) cur-entry first '()))
+ ((1) (cond
+ ((string? (car args))
+ (set-source* (current-seconds) cur-entry first (car args)))
+ ((number? (car args))
+ (set-source* (current-seconds) first (car args) '()))
+ (else (assert #f "Unsupported arg types in " (cons first args)))))
+ ((2) (cond
+ ((string? (cadr args))
+ (set-source* (current-seconds) first (car args) (cadr args)))
+ ((number? (cadr args))
+ (set-source* first (car args) (cadr args) '()))
+ (else (assert #f "Unsupported arg types in " (cons first args)))))
+ ((3) (set-descr* first (car args) (cadr args) (caddr args)))
+ (else (assert #f "Too many arguments to set-source " (cons first args)))))
+
+(define (set-title* mtime entry-id title)
+ (trace `(set-title ,mtime ,entry-id ,title))
+ (unless-protected entry-id
+ (exec (sql db "UPDATE entry SET title=?, mtime=? WHERE id=?;")
+ title mtime entry-id)))
+
+(defcmd (set-title first . args)
+ "[[mtime] entry-id] title" "Sets entry title"
+ (case (length args)
+ ((0) (set-title* (current-seconds) cur-entry first))
+ ((1) (set-title* (current-seconds) first (car args)))
+ ((2) (set-title* first (car args) (cadr args)))
+ (else (assert #f "Too many arguments to set-title " (cons first args)))))
+
(defcmd (set-entry arg)
"entry-id|url" "Set current entry"
(cond ((integer? arg)