Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve OpenGraph information with adjusted HTML export #1

Merged
merged 16 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 35 additions & 26 deletions data/templates/html/rules.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ body {

.RulesContent {
grid-column: 2;
margin-left: 1em;
counter-reset: hdr_counter;
}

Expand All @@ -25,8 +26,16 @@ body {
counter-reset: rule_counter;
list-style: none;
line-height: 1.5em;
margin-left: 3.5em;
text-indent: -3.5em;
margin-left: 4em;
margin-top: 0;
/* text-indent: -3.5em; */
}

.Rule a.RuleLink {
display: inline-block;
width: 0;
position: relative;
left:-3em;
}

.SubType {
Expand All @@ -37,7 +46,7 @@ body {
counter-reset: sub_rule_counter;
list-style: none;
line-height: 1.5em;
text-indent: -1.5em;
/* text-indent: -1.5em; */
}

.SubSection {
Expand All @@ -46,29 +55,29 @@ body {
font-size: 1.2em;
}

.Chapter:before {
content: counter(hdr_counter) ".";
counter-increment: hdr_counter;
padding-right: 10px;
}
/* .Chapter:before { */
/* content: counter(hdr_counter) "."; */
/* counter-increment: hdr_counter; */
/* padding-right: 10px; */
/* } */

.Section:before {
content: counter(hdr_counter) "." counter(sec_counter) ".";
counter-increment: sec_counter;
padding-right: 10px;
}
/* .Section:before { */
/* content: counter(hdr_counter) "." counter(sec_counter) "."; */
/* counter-increment: sec_counter; */
/* padding-right: 10px; */
/* } */

.Rule:before {
content: counter(hdr_counter) "." counter(sec_counter) "." counter(rule_counter) ".";
counter-increment: rule_counter;
padding-right: 10px;
}
/* .Rule:before { */
/* content: counter(hdr_counter) "." counter(sec_counter) "." counter(rule_counter) "."; */
/* counter-increment: rule_counter; */
/* padding-right: 10px; */
/* } */

.SubRule:before {
content: counters(sub_rule_counter, "", lower-alpha) ".";
counter-increment: sub_rule_counter;
padding-right: 10px;
}
/* .SubRule:before { */
/* content: counters(sub_rule_counter, "", lower-alpha) "."; */
/* counter-increment: sub_rule_counter; */
/* padding-right: 10px; */
/* } */

.Card {
font-style: italic;
Expand All @@ -92,15 +101,15 @@ body {
}

.ExamplesSubRule {
margin-left: -1.5em;
/* margin-left: -1.5em; */
}

.ExamplesRule {
margin-left: -3.6em;
/* margin-left: -3.6em; */
}

.ExamplesSubSection {
margin-left: -6em;
/* margin-left: -6em; */
}

.Examples {
Expand Down
16 changes: 16 additions & 0 deletions data/templates/html/rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
addEventListener("load", (event) => {
const urlParams = new URLSearchParams(window.location.search);
const ruleID = urlParams.get('r');
document.getElementById(ruleID).scrollIntoView();
lostgeek marked this conversation as resolved.
Show resolved Hide resolved
});

// Prevent reloading page while following rules links
// The rule link still appears in the user's navigation bar to copy and paste
const $elems = document.querySelectorAll('a.RuleLink')
var elems = Array.from($elems)
elems.map(a => {
lostgeek marked this conversation as resolved.
Show resolved Hide resolved
a.onclick = (e) => {
e.preventDefault()
history.replaceState(null, null, a.href)
}
})
lostgeek marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion rules_doc_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
print("Ready!")

shutil.copyfile(os.path.join('data', 'images', 'credit.svg'), os.path.join('html', 'credit.svg'))
shutil.copyfile(os.path.join('data', 'templates', 'html', 'rules.css'), os.path.join('html', 'rules.css'))
shutil.copyfile(os.path.join('data', 'templates', 'html', 'rules.css'), os.path.join('html', 'rules.css'))
shutil.copyfile(os.path.join('data', 'templates', 'html', 'rules.js'), os.path.join('html', 'rules.js'))
2 changes: 1 addition & 1 deletion rules_doc_generator/model/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_toc_html(id_map: RefDict):
return result

def standalone_html(document: Document, config: Config, id_map: RefDict):
result = '<!DOCTYPE html><html><head><link rel="stylesheet" href="rules.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible"></head><body>'
result = '<!DOCTYPE html><html><head><script src="rules.js" defer></script><link rel="stylesheet" href="rules.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible"></head><body>'
result += '<div class="RulesGrid">'
result += f'<ul class="RulesToc">{create_toc_html(id_map)}</ul>'
result += f'<div class="RulesContent">{document.to_html(config, id_map)}</div>'
Expand Down
8 changes: 5 additions & 3 deletions rules_doc_generator/model/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,12 @@ def to_html(self, config: Config, id_map: RefDict) -> str:
if self.snippet:
result += f'<p class="Snippet">{self.snippet.to_html(config, id_map)}</p>'
result += '<ol class="Rules">'
for elem in self.section_elements:
for n, elem in enumerate(self.section_elements):
rulenr:str = f'{id_map[self.id].reference}.{n+1}.'

match elem:
case Rule(): result += f'<li class="Rule" id="{elem.id}">{elem.to_html(config, id_map)}</li>'
case SubSection(): result += f'<li class="Rule" id="{elem.id}">{elem.to_html(config, id_map)}</li>'
case Rule(): result += f'<li class="Rule" id="{elem.id}"><a class="RuleAnchor" href="#{elem.id}"></a><a class="RuleLink" href="?r={elem.id}">{rulenr}</a>{elem.to_html(config, id_map)}</li>'
lostgeek marked this conversation as resolved.
Show resolved Hide resolved
case SubSection(): result += f'<li class="Rule" id="{elem.id}"><a class="RuleAnchor" href="#{elem.id}"></a><a class="RuleLink" href="?r={elem.id}">{rulenr}</a>{elem.to_html(config, id_map)}</li>'
case TimingStructure(): result += elem.to_html(config, id_map)
result += '</ol>'
return result
Expand Down