mirror of
https://github.com/correl/melpa.git
synced 2024-12-23 19:19:51 +00:00
Use archive.json to populate the html package index, rather than ad-hoc sexp parsing
This commit is contained in:
parent
7944652cb7
commit
fdae5acf11
4 changed files with 47 additions and 32 deletions
2
Makefile
2
Makefile
|
@ -17,7 +17,7 @@ build:
|
||||||
$(EVAL) "(package-build-all)"
|
$(EVAL) "(package-build-all)"
|
||||||
|
|
||||||
html: index
|
html: index
|
||||||
index:
|
index: archive.json
|
||||||
@echo " • Building html index ..."
|
@echo " • Building html index ..."
|
||||||
$(MAKE) -C $(HTMLDIR)
|
$(MAKE) -C $(HTMLDIR)
|
||||||
|
|
||||||
|
|
|
@ -11,43 +11,22 @@
|
||||||
**Last Update:** *<%= Time.now.strftime("%Y.%m.%d %H:%M %z") %>*
|
**Last Update:** *<%= Time.now.strftime("%Y.%m.%d %H:%M %z") %>*
|
||||||
|
|
||||||
<%
|
<%
|
||||||
def parse str
|
require 'json'
|
||||||
# credit to: http://stackoverflow.com/q/3128406/154508
|
archive_json = JSON.parse(File.open("../archive.json").read)
|
||||||
tokens = str.scan(/#{Regexp.escape("(")}|#{Regexp.escape(")")}|"(?:\\.|[^"])+"|[a-zA-Z0-9\'\-\_\+]+/)
|
|
||||||
|
|
||||||
stack = [[]]
|
|
||||||
|
|
||||||
tokens.each do |tok|
|
|
||||||
case tok
|
|
||||||
when "("
|
|
||||||
stack << []
|
|
||||||
when ")"
|
|
||||||
stack[-2] << stack.pop
|
|
||||||
when /^"(.*)\"$/
|
|
||||||
stack[-1] << $1
|
|
||||||
else
|
|
||||||
stack[-1] << tok
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return stack[-1][-1]
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
headers = ["Package", "Version", "Description", "Source"]
|
headers = ["Package", "Version", "Description", "Source"]
|
||||||
data = parse(File.open("../packages/archive-contents").read)[1..-1]
|
|
||||||
|
|
||||||
data.map! do |row|
|
data = archive_json.keys.sort.map do |pkgname|
|
||||||
pkgname = row[0]
|
versions, deps, descr, pkgtype = archive_json[pkgname]
|
||||||
pkgurl = "packages/#{row[0]}-#{row[1]}." + (row[-1] == "single" ? "el" : "tar")
|
version = versions.max.to_s
|
||||||
|
pkgurl = "packages/#{pkgname}-#{version}." + (pkgtype == "single" ? "el" : "tar")
|
||||||
recipe_url = "https://github.com/milkypostman/melpa/blob/master/recipes/#{pkgname}"
|
recipe_url = "https://github.com/milkypostman/melpa/blob/master/recipes/#{pkgname}"
|
||||||
descr, source = row[3..-2].join(" "), "other"
|
source = 'unknown'
|
||||||
if descr =~ /(.*?)(\s*-\*-.*?)?\s*\[source:\s*(\w+)\]\s*/
|
if descr =~ /(.*?)(\s*-\*-.*?)?\s*\[source:\s*(\w+)\]\s*/
|
||||||
descr, source = $1, $3
|
descr, source = $1, $3
|
||||||
end
|
end
|
||||||
["[#{pkgname}](#{pkgurl})", row[1][0], descr, "[#{source}](#{recipe_url})"]
|
["[#{pkgname}](#{pkgurl})", version, descr, "[#{source}](#{recipe_url})"]
|
||||||
end
|
end
|
||||||
data.sort!
|
|
||||||
|
|
||||||
colwidth = [0,0,0, 9]
|
colwidth = [0,0,0, 9]
|
||||||
|
|
||||||
|
|
35
json-fix.el
Normal file
35
json-fix.el
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
;;; Fixes for json.el such that integer plist / alist keys are rendered as strings, in order to comply with the json spec
|
||||||
|
|
||||||
|
(require 'json)
|
||||||
|
|
||||||
|
(defun json-encode-key-value-pair (pair)
|
||||||
|
"Encode a (key . value) PAIR as JSON, ensuring that key is encoded into a string."
|
||||||
|
(let ((encoded-key (json-encode (car pair))))
|
||||||
|
(format "%s:%s"
|
||||||
|
(if (string-match "^\"" encoded-key)
|
||||||
|
encoded-key
|
||||||
|
(json-encode-string encoded-key))
|
||||||
|
(json-encode (cdr pair)))))
|
||||||
|
|
||||||
|
(defun json-encode-hash-table (hash-table)
|
||||||
|
"Return a JSON representation of HASH-TABLE."
|
||||||
|
(json-encode-alist (maphash 'cons hash-table)))
|
||||||
|
|
||||||
|
;; List encoding (including alists and plists)
|
||||||
|
|
||||||
|
(defun json-encode-alist (alist)
|
||||||
|
"Return a JSON representation of ALIST."
|
||||||
|
(format "{%s}"
|
||||||
|
(json-join (mapcar 'json-encode-key-value-pair
|
||||||
|
alist) ", ")))
|
||||||
|
|
||||||
|
(defun json-encode-plist (plist)
|
||||||
|
"Return a JSON representation of PLIST."
|
||||||
|
(json-encode-alist
|
||||||
|
(loop while plist
|
||||||
|
collect (cons (car plist) (cadr plist))
|
||||||
|
do (setf plist (cddr plist)))))
|
||||||
|
|
||||||
|
|
||||||
|
(provide 'json-fix)
|
||||||
|
;;; json-fix.el ends here
|
|
@ -650,16 +650,17 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs."
|
||||||
|
|
||||||
;; Utility functions
|
;; Utility functions
|
||||||
(autoload 'json-encode "json")
|
(autoload 'json-encode "json")
|
||||||
|
(eval-after-load 'json '(load (expand-file-name "json-fix")))
|
||||||
|
|
||||||
(defun package-build-alist-as-json (fn)
|
(defun package-build-alist-as-json (fn)
|
||||||
(interactive)
|
(interactive)
|
||||||
(with-temp-file fn
|
(with-temp-file fn
|
||||||
(insert (json-encode package-build-alist))))
|
(insert (json-encode package-build-alist))))
|
||||||
|
|
||||||
(defun package-build-archive-alist-as-json (fn)
|
(defun package-build-archive-alist-as-json (fn)
|
||||||
(interactive)
|
(interactive)
|
||||||
(with-temp-file fn
|
(with-temp-file fn
|
||||||
(insert (json-encode package-build-archive-alist))))
|
(insert (json-encode package-build-archive-alist))))
|
||||||
|
|
||||||
|
|
||||||
(provide 'package-build)
|
(provide 'package-build)
|
||||||
|
|
Loading…
Reference in a new issue