diff --git a/.github/workflows/build-site.yml b/.github/workflows/build-site.yml index 21432863..98d06131 100644 --- a/.github/workflows/build-site.yml +++ b/.github/workflows/build-site.yml @@ -48,6 +48,7 @@ jobs: run: | . nikola/bin/activate nikola build + python utils/check_documentation_urls.py output - name: Pack output run: | diff --git a/README.md b/README.md index 188f4992..227d0821 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ If, on osx, you receive this error: `FileNotFoundError: [Errno 2] No such file o **./serve.sh** : Starts a local web server that serves the site and opens it in the browser. +Builds default to `https://openframeworks.cc/` for absolute links. For a local preview with localhost URLs, explicitly set `OFSITE_SITE_URL=http://localhost:8000/` when running `nikola build`. Production builds must use the public URL. + If you plan to do a big modifications like contribute a translation the easiest is to leave the 2 last scripts running and just edit the content files and the site will automatically get refreshed. ## Documentation-style markdown diff --git a/build_server.sh b/build_server.sh index 9e701fb8..157720de 100755 --- a/build_server.sh +++ b/build_server.sh @@ -61,8 +61,12 @@ if [ -z "$SRC" ]; then echo nikola . nikola/bin/activate #nikola clean 2>> $LOG - nikola build 2>> $LOG + OFSITE_SITE_URL=https://openframeworks.cc/ nikola build 2>> $LOG ret=$? + if [ "$ret" -eq 0 ]; then + python utils/check_documentation_urls.py output 2>> $LOG + ret=$? + fi if [ $ret -ne 0 ] then SUBJECT="Failed building site" diff --git a/conf.py b/conf.py index 3bdca6eb..63a6b8b5 100644 --- a/conf.py +++ b/conf.py @@ -4,7 +4,7 @@ import os import time import markdown -import socket +import hashlib # !! This is the configuration of Nikola. !! # # !! You should edit it to your liking. !! # @@ -24,12 +24,7 @@ BLOG_TITLE = "openFrameworks" # (translatable) # This is the main URL for your site. It will be used # in a prominent link. Don't forget the protocol (http/https)! -if os.environ.get("OFSITE_SITE_URL"): - SITE_URL = os.environ["OFSITE_SITE_URL"] -elif socket.gethostbyname(socket.gethostname()) == socket.gethostbyname('openframeworks.cc'): - SITE_URL = "https://openframeworks.cc/" -else: - SITE_URL = "http://localhost:8000/" +SITE_URL = os.environ.get("OFSITE_SITE_URL") or "https://openframeworks.cc/" # This is the URL where Nikola's output will be deployed. # If not set, defaults to SITE_URL # BASE_URL = "http://openframeworks.cc/" @@ -1249,7 +1244,11 @@ # Put in global_context things you want available on all your templates. # It can be anything, data, functions, modules, etc. +with open(os.path.join(os.path.dirname(__file__), "themes/openframeworks/assets/css/style.css"), "rb") as _stylesheet: + STYLESHEET_VERSION = hashlib.sha256(_stylesheet.read()).hexdigest()[:12] + GLOBAL_CONTEXT = { + "stylesheet_version": STYLESHEET_VERSION, "currentVersion": "0.12.1", "breaking": False, "majorVersion": "0.12.1", diff --git a/themes/openframeworks/assets/css/style.css b/themes/openframeworks/assets/css/style.css index cf237ff9..491a9ece 100644 --- a/themes/openframeworks/assets/css/style.css +++ b/themes/openframeworks/assets/css/style.css @@ -1670,21 +1670,26 @@ table.tableblock #preamble>.sectionbody>.paragraph:first-of-type p{font-size:inh /* Download platform groups. */ .download-platform-group { clear: both; - background: #eee; - border: 1px solid #ddd; - padding: 24px; - margin: 0 0 20px; + margin: 0 0 30px; box-sizing: border-box; } -.download-platform-group > h2 { margin-top: 0; } +.download-platform-group > h2 { margin: 0 0 16px; } .download-platform-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); - gap: 24px; + gap: 16px; } .download-platform-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .download-platform-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } -.download-platform { min-width: 0; overflow-wrap: anywhere; } +.download-platform { + min-width: 0; + padding: 20px; + background: #eee; + border: 1px solid #ddd; + box-sizing: border-box; + overflow-wrap: anywhere; +} +.download-platform > h3 { margin-top: 0; } .download-platform p { margin: 0 0 10px; } .download-target-note { font-size: 0.9em; margin-bottom: 0; } .download-nightly { clear: both; padding-top: 12px; } diff --git a/themes/openframeworks/templates/base.tmpl b/themes/openframeworks/templates/base.tmpl index 16d13d45..86427cea 100644 --- a/themes/openframeworks/templates/base.tmpl +++ b/themes/openframeworks/templates/base.tmpl @@ -52,7 +52,7 @@ ${set_locale(lang)} - + diff --git a/themes/openframeworks/templates/documentation_index_block.mako b/themes/openframeworks/templates/documentation_index_block.mako index 72c60b4e..9b07147d 100644 --- a/themes/openframeworks/templates/documentation_index_block.mako +++ b/themes/openframeworks/templates/documentation_index_block.mako @@ -1,5 +1,9 @@ ## -*- coding: utf-8 -*- <%page args="module,classes,show_header,subtitle"/> +<% + language_path = translations[lang].strip("./") + documentation_path = ("/" + language_path if language_path else "") + "/documentation/" + module +%>
% if show_header:
@@ -22,7 +26,7 @@
    -
  • ${clazz.name}  +
  • ${clazz.name}  % if clazz.is_class(): C++ Class % else: @@ -38,7 +42,7 @@ % if len(method.description) <= 1 and len(method.inlined_description) <= 1: <% htmlclass = htmlclass + " noDoc" %> % endif -
  • ${method.name}()
  • +
  • ${method.name}()
  • <% prevmethod = method.name %> % endif % endfor @@ -55,7 +59,7 @@ % if len(variable.description) <= 1: <% htmlclass = htmlclass + " noDoc" %> % endif -
  • ${variable.name}
  • +
  • ${variable.name}
  • % endif % endfor % endif diff --git a/themes/openframeworks/templates/download.mako b/themes/openframeworks/templates/download.mako index d988bf96..15365488 100644 --- a/themes/openframeworks/templates/download.mako +++ b/themes/openframeworks/templates/download.mako @@ -144,9 +144,11 @@ $(document).ready(function(){

    Android

    - ${package_link("Android package (Windows host)", "android_windows", legacy="android_windows")} -

    Android Studio setup / NDK 29 · Latest Android Studio

    -

    For another host, use a matching source checkout and download the Android libraries as described in the setup guide.

    +
    + ${package_link("Android package (Windows host)", "android_windows", legacy="android_windows")} +

    Android Studio setup / NDK 29 · Latest Android Studio

    +

    For another host, use a matching source checkout and download the Android libraries as described in the setup guide.

    +

    Browse the ${currentVersion} release files, nightly builds, or older releases and beta releases.

    diff --git a/utils/check_documentation_urls.py b/utils/check_documentation_urls.py new file mode 100644 index 00000000..fe007d54 --- /dev/null +++ b/utils/check_documentation_urls.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +"""Reject loopback URLs in generated API reference links and search entries.""" +from html.parser import HTMLParser +from pathlib import Path +import re +import sys +from urllib.parse import urlsplit + + +def is_loopback(url): + return urlsplit(url.replace("\\/", "/")).hostname in { + "localhost", "127.0.0.1", "0.0.0.0", "::1" + } + + +class ReferenceLinks(HTMLParser): + def __init__(self): + super().__init__() + self.invalid = [] + + def handle_starttag(self, tag, attrs): + for name, value in attrs: + if name == "href" and value and is_loopback(value): + self.invalid.append((self.getpos()[0], value)) + + +def main(): + root = Path(sys.argv[1] if len(sys.argv) > 1 else "output") + files = [p for p in root.rglob("*.html") if "documentation" in p.relative_to(root).parts] + if not files: + sys.exit("No generated API documentation found in " + str(root)) + errors = [] + for path in files: + parser = ReferenceLinks() + parser.feed(path.read_text(encoding="utf-8")) + errors.extend("{}:{}: {}".format(path, line, url) for line, url in parser.invalid) + search_files = list(root.rglob("tipuesearch_content.js")) + for path in search_files: + text = path.read_text(encoding="utf-8") + for match in re.finditer(r'"url"\s*:\s*"((?:\\.|[^"\\])*)"', text): + if is_loopback(match.group(1)): + errors.append("{}: {}".format(path, match.group(1))) + if errors: + sys.exit("Loopback documentation URLs:\n" + "\n".join(errors)) + print("Checked {} API pages and {} search indexes: no loopback URLs".format(len(files), len(search_files))) + + +if __name__ == "__main__": + main()