Skip to content

Commit b1925be

Browse files
authored
Merge pull request #849 from danoli3/fix-platform-cards-and-production-links
Restore platform card backgrounds and fix localhost documentation links
2 parents 4648542 + 1ff165b commit b1925be

9 files changed

Lines changed: 88 additions & 22 deletions

File tree

‎.github/workflows/build-site.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
run: |
4949
. nikola/bin/activate
5050
nikola build
51+
python utils/check_documentation_urls.py output
5152
5253
- name: Pack output
5354
run: |

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ If, on osx, you receive this error: `FileNotFoundError: [Errno 2] No such file o
5151

5252
**./serve.sh** : Starts a local web server that serves the site and opens it in the browser.
5353

54+
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.
55+
5456
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.
5557

5658
## Documentation-style markdown

‎build_server.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ if [ -z "$SRC" ]; then
6161
echo nikola
6262
. nikola/bin/activate
6363
#nikola clean 2>> $LOG
64-
nikola build 2>> $LOG
64+
OFSITE_SITE_URL=https://openframeworks.cc/ nikola build 2>> $LOG
6565
ret=$?
66+
if [ "$ret" -eq 0 ]; then
67+
python utils/check_documentation_urls.py output 2>> $LOG
68+
ret=$?
69+
fi
6670
if [ $ret -ne 0 ]
6771
then
6872
SUBJECT="Failed building site"

‎conf.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import time
66
import markdown
7-
import socket
7+
import hashlib
88

99
# !! This is the configuration of Nikola. !! #
1010
# !! You should edit it to your liking. !! #
@@ -24,12 +24,7 @@
2424
BLOG_TITLE = "openFrameworks" # (translatable)
2525
# This is the main URL for your site. It will be used
2626
# in a prominent link. Don't forget the protocol (http/https)!
27-
if os.environ.get("OFSITE_SITE_URL"):
28-
SITE_URL = os.environ["OFSITE_SITE_URL"]
29-
elif socket.gethostbyname(socket.gethostname()) == socket.gethostbyname('openframeworks.cc'):
30-
SITE_URL = "https://openframeworks.cc/"
31-
else:
32-
SITE_URL = "http://localhost:8000/"
27+
SITE_URL = os.environ.get("OFSITE_SITE_URL") or "https://openframeworks.cc/"
3328
# This is the URL where Nikola's output will be deployed.
3429
# If not set, defaults to SITE_URL
3530
# BASE_URL = "http://openframeworks.cc/"
@@ -1249,7 +1244,11 @@
12491244

12501245
# Put in global_context things you want available on all your templates.
12511246
# It can be anything, data, functions, modules, etc.
1247+
with open(os.path.join(os.path.dirname(__file__), "themes/openframeworks/assets/css/style.css"), "rb") as _stylesheet:
1248+
STYLESHEET_VERSION = hashlib.sha256(_stylesheet.read()).hexdigest()[:12]
1249+
12521250
GLOBAL_CONTEXT = {
1251+
"stylesheet_version": STYLESHEET_VERSION,
12531252
"currentVersion": "0.12.1",
12541253
"breaking": False,
12551254
"majorVersion": "0.12.1",

‎themes/openframeworks/assets/css/style.css‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,21 +1670,26 @@ table.tableblock #preamble>.sectionbody>.paragraph:first-of-type p{font-size:inh
16701670
/* Download platform groups. */
16711671
.download-platform-group {
16721672
clear: both;
1673-
background: #eee;
1674-
border: 1px solid #ddd;
1675-
padding: 24px;
1676-
margin: 0 0 20px;
1673+
margin: 0 0 30px;
16771674
box-sizing: border-box;
16781675
}
1679-
.download-platform-group > h2 { margin-top: 0; }
1676+
.download-platform-group > h2 { margin: 0 0 16px; }
16801677
.download-platform-grid {
16811678
display: grid;
16821679
grid-template-columns: repeat(4, minmax(0, 1fr));
1683-
gap: 24px;
1680+
gap: 16px;
16841681
}
16851682
.download-platform-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
16861683
.download-platform-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
1687-
.download-platform { min-width: 0; overflow-wrap: anywhere; }
1684+
.download-platform {
1685+
min-width: 0;
1686+
padding: 20px;
1687+
background: #eee;
1688+
border: 1px solid #ddd;
1689+
box-sizing: border-box;
1690+
overflow-wrap: anywhere;
1691+
}
1692+
.download-platform > h3 { margin-top: 0; }
16881693
.download-platform p { margin: 0 0 10px; }
16891694
.download-target-note { font-size: 0.9em; margin-bottom: 0; }
16901695
.download-nightly { clear: both; padding-top: 12px; }

‎themes/openframeworks/templates/base.tmpl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ${set_locale(lang)}
5252
<script src="/assets/js/highlight.min.js"></script>
5353
<script>hljs.initHighlightingOnLoad();</script>
5454

55-
<link rel="stylesheet" type="text/css" href="/assets/css/style.css" media="all" />
55+
<link rel="stylesheet" type="text/css" href="/assets/css/style.css?v=${stylesheet_version}" media="all" />
5656

5757
<link href='https://fonts.googleapis.com/css?family=Questrial' rel='stylesheet' type='text/css'>
5858

‎themes/openframeworks/templates/documentation_index_block.mako‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## -*- coding: utf-8 -*-
22
<%page args="module,classes,show_header,subtitle"/>
3+
<%
4+
language_path = translations[lang].strip("./")
5+
documentation_path = ("/" + language_path if language_path else "") + "/documentation/" + module
6+
%>
37
<div class="documentation_group">
48
% if show_header:
59
<div class="documentation_group_head hide">
@@ -22,7 +26,7 @@
2226
<div class="box">
2327
<ul class="documentation_class">
2428
<!-- class link -->
25-
<li class="docs-module-title"><a href="${site_url}/${'/documentation/' + module + '/' + clazz.name}/" class="documentation_class_link"><strong>${clazz.name}</strong></a>&nbsp;
29+
<li class="docs-module-title"><a href="${documentation_path}/${clazz.name}/" class="documentation_class_link"><strong>${clazz.name}</strong></a>&nbsp;
2630
% if clazz.is_class():
2731
<img src="/icons/class.png" alt="C++ Class"/>
2832
% else:
@@ -38,7 +42,7 @@
3842
% if len(method.description) <= 1 and len(method.inlined_description) <= 1:
3943
<% htmlclass = htmlclass + " noDoc" %>
4044
% endif
41-
<li class="${htmlclass}"><a href="${site_url}/${'documentation/' + module + '/' + clazz.name}/#!show_${method.name.replace("_","")}" title="${method.name.replace("_","")}" class="documentation_func">${method.name}()</a></li>
45+
<li class="${htmlclass}"><a href="${documentation_path}/${clazz.name}/#!show_${method.name.replace("_","")}" title="${method.name.replace("_","")}" class="documentation_func">${method.name}()</a></li>
4246
<% prevmethod = method.name %>
4347
% endif
4448
% endfor
@@ -55,7 +59,7 @@
5559
% if len(variable.description) <= 1:
5660
<% htmlclass = htmlclass + " noDoc" %>
5761
% endif
58-
<li class="${htmlclass}"><a href="${site_url}/${'/documentation/' + module + '/' + clazz.name}/#!show_${variable.name}" title="${variable.name}" class="documentation_func">${variable.name}</a></li>
62+
<li class="${htmlclass}"><a href="${documentation_path}/${clazz.name}/#!show_${variable.name}" title="${variable.name}" class="documentation_func">${variable.name}</a></li>
5963
% endif
6064
% endfor
6165
% endif

‎themes/openframeworks/templates/download.mako‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ $(document).ready(function(){
144144
145145
<section class="download-platform-group" id="android">
146146
<h2>Android</h2>
147-
${package_link("Android package (Windows host)", "android_windows", legacy="android_windows")}
148-
<p><a href="../setup/android-studio/">Android Studio setup / NDK 29</a> · <a href="https://developer.android.com/studio">Latest Android Studio</a></p>
149-
<p class="download-target-note">For another host, use a matching source checkout and download the Android libraries as described in the setup guide.</p>
147+
<div class="download-platform">
148+
${package_link("Android package (Windows host)", "android_windows", legacy="android_windows")}
149+
<p><a href="../setup/android-studio/">Android Studio setup / NDK 29</a> · <a href="https://developer.android.com/studio">Latest Android Studio</a></p>
150+
<p class="download-target-note">For another host, use a matching source checkout and download the Android libraries as described in the setup guide.</p>
151+
</div>
150152
</section>
151153
152154
<p>Browse the <a href="https://github.com/openframeworks/openFrameworks/releases/tag/${currentVersion}">${currentVersion} release files</a>, <a href="${NIGHTLY_URL}">nightly builds</a>, or <a href="../download/older/">older releases and beta releases</a>.</p>

‎utils/check_documentation_urls.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
"""Reject loopback URLs in generated API reference links and search entries."""
3+
from html.parser import HTMLParser
4+
from pathlib import Path
5+
import re
6+
import sys
7+
from urllib.parse import urlsplit
8+
9+
10+
def is_loopback(url):
11+
return urlsplit(url.replace("\\/", "/")).hostname in {
12+
"localhost", "127.0.0.1", "0.0.0.0", "::1"
13+
}
14+
15+
16+
class ReferenceLinks(HTMLParser):
17+
def __init__(self):
18+
super().__init__()
19+
self.invalid = []
20+
21+
def handle_starttag(self, tag, attrs):
22+
for name, value in attrs:
23+
if name == "href" and value and is_loopback(value):
24+
self.invalid.append((self.getpos()[0], value))
25+
26+
27+
def main():
28+
root = Path(sys.argv[1] if len(sys.argv) > 1 else "output")
29+
files = [p for p in root.rglob("*.html") if "documentation" in p.relative_to(root).parts]
30+
if not files:
31+
sys.exit("No generated API documentation found in " + str(root))
32+
errors = []
33+
for path in files:
34+
parser = ReferenceLinks()
35+
parser.feed(path.read_text(encoding="utf-8"))
36+
errors.extend("{}:{}: {}".format(path, line, url) for line, url in parser.invalid)
37+
search_files = list(root.rglob("tipuesearch_content.js"))
38+
for path in search_files:
39+
text = path.read_text(encoding="utf-8")
40+
for match in re.finditer(r'"url"\s*:\s*"((?:\\.|[^"\\])*)"', text):
41+
if is_loopback(match.group(1)):
42+
errors.append("{}: {}".format(path, match.group(1)))
43+
if errors:
44+
sys.exit("Loopback documentation URLs:\n" + "\n".join(errors))
45+
print("Checked {} API pages and {} search indexes: no loopback URLs".format(len(files), len(search_files)))
46+
47+
48+
if __name__ == "__main__":
49+
main()

0 commit comments

Comments
 (0)