Function: nnrss-discover-feed

nnrss-discover-feed is a byte-compiled function defined in nnrss.el.gz.

Signature

(nnrss-discover-feed URL)

Documentation

Given a page, find an RSS feed.

Use Mark Pilgrim's ultra-liberal rss locator.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/nnrss.el.gz
(defun nnrss-discover-feed (url)
  "Given a page, find an RSS feed.
Use Mark Pilgrim's `ultra-liberal rss locator'."
  (let ((parsed-page (nnrss-fetch url)))
    ;;    1. if this url is the rss, use it.
    (if (nnrss-rss-p parsed-page)
	(let ((rss-ns (nnrss-get-namespace-prefix parsed-page "http://purl.org/rss/1.0/")))
	  (nnrss-rss-title-description rss-ns parsed-page url))

      ;;    2. look for the <link rel="alternate"
      ;;    type="application/rss+xml" and use that if it is there.
      (let ((links (nnrss-get-rsslinks parsed-page)))
	(if links
	    (let* ((xml (nnrss-fetch
			 (cdr (assoc 'href (cadar links)))))
		   (rss-ns (nnrss-get-namespace-prefix
			    xml "http://purl.org/rss/1.0/")))
	      (nnrss-rss-title-description
	       rss-ns xml (cdr (assoc 'href (cadar links)))))

	  ;;    3. look for links on the site in the following order:
	  ;;       - onsite links ending in .rss, .rdf, or .xml
	  ;;       - onsite links containing any of the above
	  ;;       - offsite links ending in .rss, .rdf, or .xml
	  ;;       - offsite links containing any of the above
	  (let* ((base-uri (progn (string-match ".*://[^/]+/?" url)
				  (match-string 0 url)))
		 (hrefs (nnrss-order-hrefs
			 base-uri (nnrss-extract-hrefs parsed-page)))
		 (rss-link nil))
	    (while (and (eq rss-link nil) (not (eq hrefs nil)))
	      (let ((href-data (nnrss-fetch (car hrefs))))
		(if (nnrss-rss-p href-data)
		    (let* ((rss-ns (nnrss-get-namespace-prefix href-data "http://purl.org/rss/1.0/")))
		      (setq rss-link (nnrss-rss-title-description
				      rss-ns href-data (car hrefs))))
		  (setq hrefs (cdr hrefs)))))
            rss-link))))))