(write-file filename)))
\f
-(defun atom-to-rss (atom)
+(defun atom-to-rss (atom &optional rss-self)
"Translate an Atom feed into an RSS one, returning the translation.
Some information may be lost or approximated."
(let ((rss (list (assoc 'title atom))))
+ (if rss-self
+ (atom-modify-entry rss 'atom:link
+ `(((href . ,rss-self) (rel . "self")
+ (type . "application/atom+xml")))))
(atom-to-rss-translator atom rss '((subtitle . description)
(updated . pubDate)
(link . link)))
(setcar (cdr guid) (list (cons 'isPermaLink "false"))))
(if (and descr
(equal (xml-get-attribute descr 'type) "xhtml"))
- (setcar (cddr descr) (xml-node-as-text descr))))
+ (setcar (cddr descr) (xml-node-as-text descr)))
+ (setcar (cdr descr) nil))
`(item nil ,@item)))
(defun atom-to-rss-translator (source target translations)
(setcar (cdr link) nil)
(setcdr (cdr link) (cons link-addr nil)))))
-(defun atom-print-as-rss (atom)
- (let ((rss (atom-to-rss atom)))
+(defun atom-print-as-rss (atom &optional rss-self)
+ (let ((rss (atom-to-rss atom rss-self)))
(insert atom-xml-declaration)
- (insert "<rss version=\"2.0\">\n")
+ ;; xmlns:atom included in order to allow the atom:link rel=self element
+ (insert "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n")
(insert " <channel>\n")
(xml-print rss " ")
(insert "\n </channel>\n")
(setcar (cddr pubDate)
(atom-to-rss-time (car (xml-node-children pubDate))))))
-(defun atom-to-rss-write-file (atom filename)
+(defun atom-to-rss-write-file (atom filename &optional rss-self)
"Saves ATOM as a RSS feed into FILENAME."
(with-temp-buffer
- (atom-print-as-rss atom)
+ (atom-print-as-rss atom rss-self)
(write-file filename)))
\f
(dolist (child (xml-node-children node))
(when (listp child) (atom-xhtml-convert-links child base))))
-(defun atom-generate-id (link creation-date)
- "Generate a string suitable for use as an atom:id element. This
-implements Mark Pilgrom's tag: URI method, using the
-CREATION-DATE of the entry, and the domain part of LINK.
-
-See <https://www.xml.com/pub/a/2004/08/18/pilgrim.html>."
- (format "tag:%s,%s:/%s"
- (url-host (url-generic-parse-url link))
- (format-time-string "%Y-%m-%d" creation-date)
- (format-time-string "%Y%m%d%H%M%S" creation-date)))
-
\f
;;; Functions that should probably not be there