aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2023-07-20 21:26:38 +1000
committerYuchen Pei <id@ypei.org>2023-07-20 21:26:38 +1000
commitfcf126f8aab283078111f8dac0b589e51f30f0ce (patch)
tree47aebf5c531ad8d57b0925d369a8a7048dac46d9
parentd94ab3b180c974682b90bd6587547b87d2da301d (diff)
Adding functions to get html url
-rw-r--r--wiki-engine.el20
-rw-r--r--wiki-markup.el10
2 files changed, 26 insertions, 4 deletions
diff --git a/wiki-engine.el b/wiki-engine.el
index 6da4ad2..74dbe15 100644
--- a/wiki-engine.el
+++ b/wiki-engine.el
@@ -29,6 +29,17 @@
(require 'wiki-utils)
(require 'wiki-markup)
+(defun wiki-engine-html-url (site title)
+ "Return the url of the html webpage of TITLE on SITE."
+ (format "%s%s" (plist-get (alist-get site wiki-sites) :base-url)
+ title))
+
+(defun wiki-current-html-url ()
+ "Return the url of the html webpage of the current wiki buffer."
+ (unless (and wiki-site wiki-title)
+ (error "Nil wiki-site or wiki-title!"))
+ (wiki-engine-html-url wiki-site wiki-title))
+
(defun wiki-engine-mediawiki-fetch (wiki-site title)
"Fetch a mediawiki entry describing TITLE.
@@ -47,7 +58,8 @@ The site handle is passed as a symbol WIKI-SITE."
(wiki-locate-dir wiki-site)
(lambda ()
(wiki-mode)
- (setq-local wiki-site wiki-site)
+ (setq-local wiki-site wiki-site
+ wiki-title title)
)
))))
@@ -65,7 +77,8 @@ The site handle is passed as a symbol WIKI-SITE."
(wiki-locate-dir wiki-site)
(lambda ()
(wiki-mode)
- (setq-local wiki-site wiki-site)
+ (setq-local wiki-site wiki-site
+ wiki-title title)
)
title))))
@@ -83,7 +96,8 @@ The site handle is passed as a symbol WIKI-SITE."
(wiki-locate-dir wiki-site)
(lambda ()
(wiki-mode)
- (setq-local wiki-site wiki-site)
+ (setq-local wiki-site wiki-site
+ wiki-title title)
)
title))))
diff --git a/wiki-markup.el b/wiki-markup.el
index f29ac52..f0f26cb 100644
--- a/wiki-markup.el
+++ b/wiki-markup.el
@@ -74,7 +74,9 @@
(defvar wiki-outline-re "=+.*=+\ *$")
(defvar-local wiki-site nil
- "The identifier of the wiki site")
+ "The identifier of the site of the current wiki buffer.")
+(defvar-local wiki-title nil
+ "The title of the current wiki buffer.")
(defun wiki-follow-wikilink-action (data)
"Button action to follow a wikilink"
(funcall (wiki-site-fetcher wiki-site) (alist-get 'target data)))
@@ -93,6 +95,11 @@ This can be overriden with .dir-locals.el."
'local))))
)
+(defun wiki-guess-title ()
+ "Guess `wiki-title' from the file name."
+ (unless wiki-title
+ (setq-local wiki-title (file-name-base (buffer-file-name)))))
+
(defun wiki-outline-level ()
(when (looking-at "\\(=+\\).*[^=]\\(=+\\)\\ *$")
(min (length (match-string 1))
@@ -261,6 +268,7 @@ This can be overriden with .dir-locals.el."
(setq-local wiki-site (intern wiki-site)))
(add-hook 'wiki-mode-hook 'wiki-guess-site)
+(add-hook 'wiki-mode-hook 'wiki-guess-title)
(provide 'wiki-markup)
;;; wiki-markup.el ends here