my eye

Fix scoreboard and screenshot

Committed e15e7e

--- a/index.js
+++ b/index.js

   const diameter = radius * 2
   const g = svg.append('g')
     .attr('transform', 'translate(' + CANVAS_SIZE/2 + ',' + CANVAS_SIZE/2 + ')')
-  const colors = ['green', 'orange', 'grey']
+  const colors = ['#008000', '#ffa500', '#666']
   const palette = []
   for (let i = 0; i < 10; i++) {
     palette[i] = colors[results[i][0]]
 }
 
 const domain = process.argv[2]
-const scores = JSON.parse(fs.readFileSync(`sites/${domain}/details.json`))["scores"];
+const scores = JSON.parse(fs.readFileSync(`sites/${domain}/scores.json`));
 const dom = new jsdom.JSDOM('<!DOCTYPE html><body></body>')
 const body = d3.select(dom.window.document.querySelector('body'))
 const svg = body.append('svg')

--- a/indieweb_rocks/__init__.py
+++ b/indieweb_rocks/__init__.py

         scores[0][2] = (2, "no posts")
 
     # L1 Search
-    if details["ddg"]:
-        scores[0][6] = (0, "your content was found on DuckDuckgo")
-    else:
-        scores[0][6] = (
-            1,
-            "your content was <strong>not</strong> found on DuckDuckgo",
-        )
+    # XXX if details["ddg"]:
+    # XXX     scores[0][6] = (0, "your content was found on DuckDuckgo")
+    # XXX else:
+    # XXX     scores[0][6] = (
+    # XXX         1,
+    # XXX         "your content was <strong>not</strong> found on DuckDuckgo",
+    # XXX     )
 
     # L1 Interactivity
     scores[0][8] = (0, "content is accessible (select/copy text/permalinks)")
     # L5 'Multiple Reply Types'
     # L5 'Display Backfeed of Comments'
 
-    details["scores"] = scores
+    update_details(scores=scores)
     # logging.debug("dumping details..")
     # details["stored"] = web.now().to_iso8601_string()
-    # web.dump(details, path=site_path / "details.json")
+    web.dump(scores, path=site_path / "scores.json")
     logging.debug("generating scoreboard..")
-    subprocess.run(["node", "../index.js", site])
+    subprocess.run(["node", "../index.js", domain])
 
 
 def get_updater(url):
     except FileNotFoundError:
         pass
     else:
+        screenshot.crop((0, 0, 1280, 1024)).save(site_path / "screenshot.png")
         colors = collections.Counter()
         for x in range(screenshot.width):
             for y in range(screenshot.height):

--- a/indieweb_rocks/__web__.py
+++ b/indieweb_rocks/__web__.py

 
 import collections
 import hashlib
+import os
 
 import easyuri
 import micropub
         raise web.flash("crawl enqueued")
 
 
-# XXX @app.control("sites/{site}/scoreboard.svg")
-# XXX class SiteScoreboard:
-# XXX     """A site's scoreboard."""
-# XXX
-# XXX     def get(self, site):
-# XXX         """Return an SVG document rendering given site's scoreboard."""
-# XXX         web.header("Content-Type", "image/svg+xml")
-# XXX         web.header("X-Accel-Redirect", f"/data/{site}/scoreboard.svg")
+@app.control("sites/{site}/screenshot.png")
+class SiteScreenshot:
+    """A site's screenshot."""
+
+    def get(self, site):
+        """Return a PNG document rendering given site's screenshot."""
+        if os.getenv("WEBCTX") == "dev":
+            return sites_path / site / "screenshot.png"
+        web.header("Content-Type", "image/png")
+        web.header("X-Accel-Redirect", f"/data/{site}/screenshot.png")
+
+
+@app.control("sites/{site}/scoreboard.svg")
+class SiteScoreboard:
+    """A site's scoreboard."""
+
+    def get(self, site):
+        """Return an SVG document rendering given site's scoreboard."""
+        if os.getenv("WEBCTX") == "dev":
+            return sites_path / site / "scoreboard.svg"
+        web.header("Content-Type", "image/svg+xml")
+        web.header("X-Accel-Redirect", f"/data/{site}/scoreboard.svg")

--- a/indieweb_rocks/templates/site.html
+++ b/indieweb_rocks/templates/site.html

     <p><em>No <a href=https://indieweb.org/representative_h-card>representative
     card</a> available.</em></p>
 
-$# <img src=/sites/$(url.minimized)/screenshot.png width=100%>
+<img src=/sites/$(url.minimized)/screenshot.png width=100%>
 
 $ license = rels.pop("license", None)
 $if license:
 
 </div>
 
-$# $def list_reasons(level):
-$#     <ul id=level$level>
-$#     $for n, (status, reason) in enumerate(details["scores"][level-1]):
-$#         $if status != 3:
-$#             <li id=$(level)-$axes[n] class=$statuses[status]>$:(reason.capitalize()).</li>
-$#     </ul>
-$# 
-$# <div id=indiemark>
-$# <object id=scoreboard data=/sites/$(url.minimized)/scoreboard.svg></object>
-$# <div style="background-color:#222;color:#999;font-size:.8em;padding:.5em 1em;">
-$# <h4>Level 1: Use your domain for identity, sign-in, and publishing posts</h4>
-$# $:list_reasons(1)
-$# <h4>Level 2: Improve your personal identity and post multiple types of posts</h4>
-$# $:list_reasons(2)
-$# <h4>Level 3: Post and send replies from your own site</h4>
-$# $:list_reasons(3)
-$# <h4>Level 4: Receive and show comments</h4>
-$# $:list_reasons(4)
-$# <h4>Level 5: Manage comments</h4>
-$# $:list_reasons(5)
-$# </div>
-$# </div>
+$def list_reasons(level):
+    <ul id=level$level>
+    $for n, (status, reason) in enumerate(details["scores"][level-1]):
+        $if status != 3:
+            <li id=$(level)-$axes[n] class=$statuses[status]>$:(reason.capitalize()).</li>
+    </ul>
+
+<div id=indiemark>
+<object id=scoreboard data=/sites/$(url.minimized)/scoreboard.svg></object>
+<div style="background-color:#222;color:#999;font-size:.8em;padding:.5em 1em;">
+<h4>Level 1: Use your domain for identity, sign-in, and publishing posts</h4>
+$:list_reasons(1)
+<h4>Level 2: Improve your personal identity and post multiple types of posts</h4>
+$:list_reasons(2)
+<h4>Level 3: Post and send replies from your own site</h4>
+$:list_reasons(3)
+<h4>Level 4: Receive and show comments</h4>
+$:list_reasons(4)
+<h4>Level 5: Manage comments</h4>
+$:list_reasons(5)
+</div>
+</div>
 
 </div>