Skip to content

Commit d996e09

Browse files
committed
fix baseurl links
1 parent 45470cf commit d996e09

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

build/build.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Converter of the e-maxx-eng project into HTML
22
33
Todos:
4-
- fix absolute links
54
- fix header links (e.g. in the Segmented Tree page)
65
- add CSS
76
- add code highlighting
@@ -16,7 +15,6 @@
1615
from contextlib import redirect_stderr
1716
import io
1817

19-
2018
import markdown # type: ignore
2119
from tqdm import tqdm # type: ignore
2220

@@ -43,6 +41,11 @@ def parse_arguments(args=None):
4341
required=True,
4442
help="path to the template file"
4543
)
44+
arg_parser.add_argument(
45+
"--baseurl",
46+
default=None,
47+
help="Base-URL of the website"
48+
)
4649
arg_parser.add_argument(
4750
"--show-progress",
4851
const=True,
@@ -58,6 +61,7 @@ class MarkdownConverter(markdown.Markdown):
5861
def __init__(self, **kwargs):
5962
template_path = kwargs.pop("template_path")
6063
self.template = template_path.read_text()
64+
self.baseurl = kwargs.pop("baseurl")
6165

6266
super().__init__(**kwargs)
6367

@@ -95,6 +99,7 @@ def convert(self, md_content: str) -> str:
9599
self.template
96100
.replace("&title&", title)
97101
.replace("&year&", str(datetime.now().year))
102+
.replace("&baseurl&", self.baseurl)
98103
.replace("&text&", html_content)
99104
)
100105

@@ -110,13 +115,16 @@ def main():
110115
"markdown_math_escape", # support for math formula
111116
"mdx_linkify", # convert text that looks like links into links
112117
]
118+
baseurl = args.baseurl or f"{args.output_dir}/"
113119
md = MarkdownConverter(
114120
extensions=extensions,
115-
template_path=args.template_path
121+
template_path=args.template_path,
122+
baseurl=baseurl
116123
)
117124

118125
input_paths = list(args.input_dir.glob("**/*.md"))
119126
for input_path in tqdm(input_paths, disable=not args.show_progress):
127+
relative_path = input_path.relative_to(args.input_dir)
120128
# read
121129
md_content = input_path.read_text()
122130

@@ -125,11 +133,10 @@ def main():
125133
with redirect_stderr(f):
126134
html_content = md.convert(md_content)
127135
if f.getvalue():
128-
print(input_path.relative_to(args.input_dir))
136+
print(relative_path)
129137
print(f.getvalue())
130138

131139
# write
132-
relative_path = input_path.relative_to(args.input_dir)
133140
output_path = args.output_dir / relative_path.with_suffix(".html")
134141
output_path.parent.mkdir(parents=True, exist_ok=True)
135142
output_path.write_text(html_content)

src/_templates/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<div id="container">
2828
<div id="navbar">
2929
<span id="title">
30-
<a href="./">CP-Algorithms</a>
30+
<a href="./index.html">CP-Algorithms</a>
3131
</span>
3232
<span id="menu">
3333
<a href="&history&" title="Changes History">Page Authors</a>

src/algebra/extended-euclid-algorithm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--?title Extended Euclidean Algorithm -->
22
# Extended Euclidean Algorithm
33

4-
While the [Euclidean algorithm](../algebra/euclid-algorithm.html) calculates only the greatest common divisor (GCD) of two integers $a$ and $b$, the extended version also finds a way to represent GCD in terms of $a$ and $b$, i.e. coefficients $x$ and $y$ for which:
4+
While the [Euclidean algorithm](./algebra/euclid-algorithm.html) calculates only the greatest common divisor (GCD) of two integers $a$ and $b$, the extended version also finds a way to represent GCD in terms of $a$ and $b$, i.e. coefficients $x$ and $y$ for which:
55

66
$$a \cdot x + b \cdot y = \gcd(a, b)$$
77

src/algebra/phi-function.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The following properties of Euler totient function are sufficient to calculate i
2323

2424
- If $a$ and $b$ are relatively prime, then:
2525
$$\phi(a b) = \phi(a) \cdot \phi(b).$$
26-
This relation is not trivial to see. It follows from the [Chinese remainder theorem](../algebra/chinese-remainder-theorem.html). The Chinese remainder theorem guarantees, that for each $0 \le x < a$ and each $0 \le y < b$, there exists a unique $0 \le z < a b$ with $z \equiv x \pmod{a}$ and $z \equiv y \pmod{b}$. It's not hard to show that $z$ is coprime to $a b$ if and only if $x$ is coprime to $a$ and $y$ is coprime to $b$. Therefore the amount of integers coprime to $a b$ is equal to product of the amounts of $a$ and $b$.
26+
This relation is not trivial to see. It follows from the [Chinese remainder theorem](./algebra/chinese-remainder-theorem.html). The Chinese remainder theorem guarantees, that for each $0 \le x < a$ and each $0 \le y < b$, there exists a unique $0 \le z < a b$ with $z \equiv x \pmod{a}$ and $z \equiv y \pmod{b}$. It's not hard to show that $z$ is coprime to $a b$ if and only if $x$ is coprime to $a$ and $y$ is coprime to $b$. Therefore the amount of integers coprime to $a b$ is equal to product of the amounts of $a$ and $b$.
2727

2828
- In general, for not coprime $a$ and $b$, the equation $$\phi(ab) = \phi(a) \cdot \phi(b) \cdot \dfrac{d}{\phi(d)}$$ with $d = \gcd(a, b)$ holds.
2929

@@ -121,7 +121,7 @@ $$a^{\phi(m)} \equiv 1 \pmod m$$ if $a$ and $m$ are relatively prime.
121121
In the particular case when $m$ is prime, Euler's theorem turns into **Fermat's little theorem**:
122122
$$a^{m - 1} \equiv 1 \pmod m$$
123123
124-
Euler's theorem and Euler's totient function occur quite often in practical applications, for example both are used to compute the [modular multiplicative inverse](../algebra/module-inverse.html).
124+
Euler's theorem and Euler's totient function occur quite often in practical applications, for example both are used to compute the [modular multiplicative inverse](./algebra/module-inverse.html).
125125
126126
As immediate consequence we also get the equivalence:
127127
$$a^n \equiv a^{n \bmod \phi(m)} \pmod m$$

src/algebra/primality_tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Multiple such optimizations are described in the article about [integer factoriz
3232
3333
This is a probabilistic test.
3434
35-
Fermat's little theorem (see also [Euler's totient function](https://cp-algorithms.com/algebra/phi-function.html)) states, that for a prime number $p$ and a coprime integer $a$ the following equation holds:
35+
Fermat's little theorem (see also [Euler's totient function](./algebra/phi-function.html)) states, that for a prime number $p$ and a coprime integer $a$ the following equation holds:
3636
3737
$$a^{p-1} \equiv 1 \bmod p$$
3838

src/sequences/rmq.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
You are given an array $A[1..N]$.
66
You have to answer incoming queries of the form $(L, R)$, which ask to find the minimum element in array $A$ between positions $L$ and $R$ inclusive.
77

8-
RMQ can appear in problems directly or can be applied in some other tasks, e.g. the [Lowest Common Ancestor](../graph/lca.html) problem.
8+
RMQ can appear in problems directly or can be applied in some other tasks, e.g. the [Lowest Common Ancestor](./graph/lca.html) problem.
99

1010
## Solution
1111

@@ -15,20 +15,20 @@ The ones that are explained on this site are listed below.
1515

1616
First the approaches that allow modifications to the array between answering queries.
1717

18-
- [Sqrt-decomposition](../data_structures/sqrt_decomposition.html) - answers each query in $O(\sqrt{N})$, preprocessing done in $O(N)$.
18+
- [Sqrt-decomposition](./data_structures/sqrt_decomposition.html) - answers each query in $O(\sqrt{N})$, preprocessing done in $O(N)$.
1919
Pros: a very simple data structure. Cons: worse complexity.
20-
- [Segment tree](../data_structures/segment_tree.html) - answers each query in $O(\log N)$, preprocessing done in $O(N)$.
20+
- [Segment tree](./data_structures/segment_tree.html) - answers each query in $O(\log N)$, preprocessing done in $O(N)$.
2121
Pros: good time complexity. Cons: larger amount of code compared to the other data structures.
22-
- [Fenwick tree](../data_structures/fenwick.html) - answers each query in $O(\log N)$, preprocessing done in $O(N \log N)$.
22+
- [Fenwick tree](./data_structures/fenwick.html) - answers each query in $O(\log N)$, preprocessing done in $O(N \log N)$.
2323
Pros: the shortest code, good time complexity. Cons: Fenwick tree can only be used for queries with $L = 1$, so it is not applicable to many problems.
2424

2525
And here are the approaches that only work on static arrays, i.e. it is not possible to change a value in the array without recomputing the complete data structure.
2626

27-
- [Sparse Table](../data_structures/sparse-table.html) - answers each query in $O(1)$, preprocessing done in $O(N \log N)$.
27+
- [Sparse Table](./data_structures/sparse-table.html) - answers each query in $O(1)$, preprocessing done in $O(N \log N)$.
2828
Pros: simple data structure, excellent time complexity.
29-
- [Sqrt Tree](../data_structures/sqrt-tree.html) - answers queries in $O(1)$, preprocessing done in $O(N \log \log N)$. Pros: fast. Cons: Complicated to implement.
30-
- [Disjoint Set Union / Arpa's Trick](../data_structures/disjoint_set_union.html#arpa) - answers queries in $O(1)$, preprocessing in $O(n)$. Pros: short, fast. Cons: only works if all queries are known in advance, i.e. only supports off-line processing of the queries.
31-
- [Cartesian Tree](../graph/rmq_linear.html) and [Farach-Colton and Bender algorithm](../graph/lca_farachcoltonbender.html) - answers queries in $O(1)$, preprocessing in $O(n)$. Pros: optimal complexity. Cons: large amount of code.
29+
- [Sqrt Tree](./data_structures/sqrt-tree.html) - answers queries in $O(1)$, preprocessing done in $O(N \log \log N)$. Pros: fast. Cons: Complicated to implement.
30+
- [Disjoint Set Union / Arpa's Trick](./data_structures/disjoint_set_union.html#arpa) - answers queries in $O(1)$, preprocessing in $O(n)$. Pros: short, fast. Cons: only works if all queries are known in advance, i.e. only supports off-line processing of the queries.
31+
- [Cartesian Tree](./graph/rmq_linear.html) and [Farach-Colton and Bender algorithm](./graph/lca_farachcoltonbender.html) - answers queries in $O(1)$, preprocessing in $O(n)$. Pros: optimal complexity. Cons: large amount of code.
3232

3333
Note: Preprocessing is the preliminary processing of the given array by building the corresponding data structure for it.
3434

0 commit comments

Comments
 (0)