emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] scratch/elpa-admin 160b4fd93d 1/3: (elpaa--make-atom-feed): Avoid


From: Stefan Monnier
Subject: [elpa] scratch/elpa-admin 160b4fd93d 1/3: (elpaa--make-atom-feed): Avoid parsing the `elpaa--url`
Date: Wed, 8 May 2024 14:24:11 -0400 (EDT)

branch: scratch/elpa-admin
commit 160b4fd93dd6b271d2543b41ac6df93f65faf8e1
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    (elpaa--make-atom-feed): Avoid parsing the `elpaa--url`
    
    * elpa-admin.el (elpaa--make-atom-feed): Don't split the URL into
    domain+path any more.  Use names relative to the current dir instead.
    (elpaa--rfc4151): New function.
    (elpaa--render-atom): Use it.
---
 elpa-admin.el | 67 +++++++++++++++++++++++++++++------------------------------
 1 file changed, 33 insertions(+), 34 deletions(-)

diff --git a/elpa-admin.el b/elpa-admin.el
index ef17fca8ea..d7be703c49 100644
--- a/elpa-admin.el
+++ b/elpa-admin.el
@@ -1879,15 +1879,13 @@ arbitrary code."
 
 (defun elpaa--make-atom-feed (pkg pkg-spec srcdir files)
   (let* ((name (symbol-name (car pkg)))
-         (path (if (string-match "\\`https?://[^/]+/\\(.*\\)" elpaa--url)
-                   (match-string 1 elpaa--url)
-                 (error "Failed to infer path from %S" elpaa--url)))
          (metadata (elpaa--metadata srcdir pkg-spec))
+         (filename (concat name ".xml"))
          (desc (nth 2 metadata)))
     (with-temp-buffer
       (elpaa--render-atom
        (format "Update feed for %s" name)
-       (concat "/" path  name ".xml")
+       filename
        (mapcan
         (lambda (file)
           (let ((version (car file)))
@@ -1895,7 +1893,7 @@ arbitrary code."
                                 elpaa--name name version)
                 :time ,(file-attribute-modification-time
                         (file-attributes (cdr file)))
-                :path ,(format "%s%s.xml#v%s" path name version)
+                :path ,(format "%s.xml#v%s" name version)
                 :content
                 ((p nil
                     ,(concat "Version " version " of package ")
@@ -1905,7 +1903,7 @@ arbitrary code."
                  (p nil ,(concat name " describes itself as:"))
                  (blockquote nil ,desc))))))
         files))
-      (write-region (point-min) (point-max) (concat name ".xml")))))
+      (write-region (point-min) (point-max) filename))))
 
 (defun elpaa--html-make-pkg (pkg pkg-spec files srcdir plain-readme)
   (let* ((name (symbol-name (car pkg)))
@@ -3195,22 +3193,26 @@ relative to elpa root."
 (defun elpaa--rfc3339 (time)
   (format-time-string "%Y-%m-%dT%H:%M:%SZ" time))
 
-(defun elpaa--render-atom (title path articles)
+(defun elpaa--rfc4151 (url time)
+  (unless (string-match "\\`\\(?:[^:/]*:\\)?/*\\([^/]+\\)/?" url)
+    (error "Can't find the \"domain\" of this URL: %S" url))
+  (let ((domain (match-string 1 url))
+        (specific (substring url (match-end 0))))
+    (concat "tag:" domain "," (format-time-string "%F" time)
+            ":" specific)))
+
+(defun elpaa--render-atom (title filename articles)
   "Insert an Atom feed at point.
-TITLE sets the title of the feed, PATH is the request path
-relative to the server route of where the Atom feed will be
-hosted.  ARTICLES is a list of plists, consisting of the keys
+TITLE sets the title of the feed, FILENAME is where the Atom feed will be
+stored.  ARTICLES is a list of plists, consisting of the keys
 `:title' for an article title, `:time' a timestamp in in
-`current-time'-format, `:path' is a root-relative HTTP path to
+`current-time'-format, `:path' is a relative HTTP path to
 the article."
   (cl-flet ((newer-p (a1 a2)
               (time-less-p (plist-get a1 :time) (plist-get a2 :time))))
     ;; FIXME: Why do we need to split elpaa--url into a domain and a path?
     (let* ((articles (sort articles #'newer-p))
-           (domain (if (string-match "\\`https?://\\([^/]+/\\)" elpaa--url)
-                       (match-string 1 elpaa--url)
-                     (error "Failed to infer domain from %S" elpaa--url)))
-           (self (concat "https://"; domain path)))
+           (self (concat elpaa--url filename)))
       (insert "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
       (xml-print
        ;; See https://validator.w3.org/feed/docs/rfc4287.html
@@ -3223,25 +3225,22 @@ the article."
           ,@(mapcar
              (pcase-lambda ((map (:title title) (:time time)
                                  (:path path) (:content content)))
-               `(entry
-                 nil
-                 (title nil ,title)
-                 (updated nil ,(elpaa--rfc3339 time))
-                 (author
-                  nil
-                  (name nil "elpa-admin")
-                  (email nil "emacs-devel@gnu.org"))
-                 (id nil ,(format "tag:%s,%s:%s"
-                                  domain
-                                  (format-time-string "%F" time)
-                                  path))
-                 (link ((href . ,(concat "https://"; domain path))
-                        (rel . "self")))
-                 (content
-                  ((type . "html"))
-                  ,(with-temp-buffer
-                     (xml-print content)
-                     (buffer-string)))))
+               (let ((self (concat elpaa--url path)))
+                 `(entry
+                   nil
+                   (title nil ,title)
+                   (updated nil ,(elpaa--rfc3339 time))
+                   (author
+                    nil
+                    (name nil "elpa-admin")
+                    (email nil "emacs-devel@gnu.org"))
+                   (id nil ,(elpaa--rfc4151 self time))
+                   (link ((href . ,self) (rel . "self")))
+                   (content
+                    ((type . "html"))
+                    ,(with-temp-buffer
+                       (xml-print content)
+                       (buffer-string))))))
              articles)))))))
 
 (defun elpaa--make-aggregated-atom-feed (filename)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]