mirror of
https://github.com/correl/melpa.git
synced 2024-12-23 11:14:57 +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)"
|
||||
|
||||
html: index
|
||||
index:
|
||||
index: archive.json
|
||||
@echo " • Building html index ..."
|
||||
$(MAKE) -C $(HTMLDIR)
|
||||
|
||||
|
|
|
@ -11,43 +11,22 @@
|
|||
**Last Update:** *<%= Time.now.strftime("%Y.%m.%d %H:%M %z") %>*
|
||||
|
||||
<%
|
||||
def parse str
|
||||
# credit to: http://stackoverflow.com/q/3128406/154508
|
||||
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
|
||||
|
||||
require 'json'
|
||||
archive_json = JSON.parse(File.open("../archive.json").read)
|
||||
|
||||
headers = ["Package", "Version", "Description", "Source"]
|
||||
data = parse(File.open("../packages/archive-contents").read)[1..-1]
|
||||
|
||||
data.map! do |row|
|
||||
pkgname = row[0]
|
||||
pkgurl = "packages/#{row[0]}-#{row[1]}." + (row[-1] == "single" ? "el" : "tar")
|
||||
data = archive_json.keys.sort.map do |pkgname|
|
||||
versions, deps, descr, pkgtype = archive_json[pkgname]
|
||||
version = versions.max.to_s
|
||||
pkgurl = "packages/#{pkgname}-#{version}." + (pkgtype == "single" ? "el" : "tar")
|
||||
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*/
|
||||
descr, source = $1, $3
|
||||
end
|
||||
["[#{pkgname}](#{pkgurl})", row[1][0], descr, "[#{source}](#{recipe_url})"]
|
||||
["[#{pkgname}](#{pkgurl})", version, descr, "[#{source}](#{recipe_url})"]
|
||||
end
|
||||
data.sort!
|
||||
|
||||
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
|
||||
(autoload 'json-encode "json")
|
||||
(eval-after-load 'json '(load (expand-file-name "json-fix")))
|
||||
|
||||
(defun package-build-alist-as-json (fn)
|
||||
(interactive)
|
||||
(with-temp-file fn
|
||||
(insert (json-encode package-build-alist))))
|
||||
(insert (json-encode package-build-alist))))
|
||||
|
||||
(defun package-build-archive-alist-as-json (fn)
|
||||
(interactive)
|
||||
(with-temp-file fn
|
||||
(insert (json-encode package-build-archive-alist))))
|
||||
(insert (json-encode package-build-archive-alist))))
|
||||
|
||||
|
||||
(provide 'package-build)
|
||||
|
|
Loading…
Reference in a new issue