Skip to content

Commit

Permalink
Add backlink generation
Browse files Browse the repository at this point in the history
  • Loading branch information
h33p committed Dec 4, 2023
1 parent 20e0acd commit ae3645d
Showing 3 changed files with 21 additions and 10 deletions.
19 changes: 15 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@
# Define custom variables passed over to the templates
template_vars = {
'navbar': [
('/', 'Home'),
('/about', 'About'),
('/quick_start', 'Quick start guide'),
('/docs', 'Documentation'),
('', 'Home'),
('about', 'About'),
('quick_start', 'Quick start guide'),
('docs', 'Documentation'),
]
}

@@ -50,6 +50,17 @@
pre += '/index'
of = pre + ".html"
os.makedirs(os.path.dirname(of), exist_ok=True)

# Build a backlink to root
offset2 = of[len(out_dir):]
if offset2.startswith('/'):
offset2 = offset2[1:]
backlink = ''
for i in range(1,len(offset2.split("/"))):
backlink += '../'

template_vars['backlink'] = backlink

content = str.encode(template.render(template_vars, content=content.decode('utf-8')))
elif ext == '.scss':
of = pre + ".css"
8 changes: 4 additions & 4 deletions src/styles.scss
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ body {
.logo {
display: inline-block;
text-align: left;
color: $logo;
color: $logo;
}

.root {
@@ -50,11 +50,11 @@ body {
margin: 30px;
width: calc(min(90vw, max(50vw, 20cm)));
max-width: calc(max(60vw, 30cm));
doverflow: hidden;
doverflow: hidden;
}

.content img {
max-width: 100%;
max-width: 100%;
}

// Github users
@@ -163,7 +163,7 @@ h4 {
background-color: #1e1e1e;
pre {
padding: 7px;
margin: 0;
margin: 0;
overflow: scroll;
overflow-x: auto;
overflow-y: hidden;
4 changes: 2 additions & 2 deletions templates/main.html
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<title>memflow project</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="/styles.css"></head>
<link rel="stylesheet" href="{{ backlink }}styles.css"></head>
</head>
<body>
<div class="root">
@@ -18,7 +18,7 @@
/_/ /_/ /_/\___/_/ /_/ /_/_/ /_/\____/|__/|__/</pre>
<ul class="navbar">
{% for link, title in navbar %}
<a href={{ link }}>{{ title }}</a>
<a href={{backlink}}{{ link }}>{{ title }}</a>
{%- if not loop.last %}
<pre> | </pre>
{% endif %}

0 comments on commit ae3645d

Please sign in to comment.