diff --git a/Makefile b/Makefile index 386f1a0aa34..851b94f7ded 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ build: $(EVAL) "(package-build-all)" html: index -index: +index: archive.json @echo " • Building html index ..." $(MAKE) -C $(HTMLDIR) diff --git a/html/index.erb b/html/index.erb index dc6e8496255..31143233382 100644 --- a/html/index.erb +++ b/html/index.erb @@ -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] diff --git a/json-fix.el b/json-fix.el new file mode 100644 index 00000000000..e56f6b333cc --- /dev/null +++ b/json-fix.el @@ -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 diff --git a/package-build.el b/package-build.el index 2a58cb17701..35a0f58dc08 100644 --- a/package-build.el +++ b/package-build.el @@ -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)