mirror of
https://github.com/benjaminion/upgrading-ethereum-book.git
synced 2026-01-09 14:38:08 -05:00
Add seq number and modify image paths
This commit is contained in:
143
bin/split.awk
143
bin/split.awk
@@ -3,77 +3,92 @@
|
||||
BEGIN{
|
||||
n = 0
|
||||
filename_prefix = "markdown-pages/pages"
|
||||
filename = ""
|
||||
filename = filename_prefix "/error.md"
|
||||
h_part = ""
|
||||
h_chapter = ""
|
||||
h_part_no = -1 # Number parts from 0
|
||||
h_chapter_no = 0
|
||||
h_section_no = 0
|
||||
}
|
||||
{
|
||||
# Headings with an HTML comment at the end trigger a new page
|
||||
if ($0 ~ /(^# |^## |^### ).* <!-- .* -->$/) {
|
||||
|
||||
# Start a new page
|
||||
if (n > 0) {
|
||||
close (filename)
|
||||
}
|
||||
n = 1
|
||||
# Headings with an HTML comment at the end trigger a new page
|
||||
/^(# |## |### ).* <!-- .* -->$/ {
|
||||
|
||||
# Generate header contents
|
||||
name = gensub("^#+ (.*) <!-- .* -->$", "\\1", "1", $0)
|
||||
h_path = gensub("^#+ .* <!-- (.*) -->$", "\\1", "1", $0)
|
||||
heading = gensub ("^(#+ .*) <!-- .* -->$", "\\1", "1", $0)
|
||||
|
||||
# Is this page hidden?
|
||||
if (h_path ~ /\*$/) {
|
||||
h_path = substr(h_path, 1, length(h_path) - 1)
|
||||
h_hide = "true"
|
||||
} else {
|
||||
h_hide = "false"
|
||||
}
|
||||
|
||||
# Make filesystem path for writing the file
|
||||
file_path = h_path
|
||||
sub(/\/[^/]+$/, "", file_path)
|
||||
system("mkdir -p " filename_prefix file_path " 2>/dev/null")
|
||||
filename = filename_prefix h_path ".md"
|
||||
|
||||
print filename
|
||||
|
||||
switch ($0) {
|
||||
case /^# /:
|
||||
h_part = name
|
||||
h_chapter = ""
|
||||
h_section = ""
|
||||
h_part_no++
|
||||
h_chapter_no = 0
|
||||
idx = h_part_no
|
||||
break
|
||||
case /^## /:
|
||||
h_chapter = name
|
||||
h_section = ""
|
||||
h_chapter_no++
|
||||
h_section_no = 0
|
||||
idx = h_part_no "," h_chapter_no
|
||||
break
|
||||
case /^### /:
|
||||
h_section = name
|
||||
h_section_no++
|
||||
idx = h_part_no "," h_chapter_no "," h_section_no
|
||||
break
|
||||
default:
|
||||
print "Internal error"
|
||||
exit (1)
|
||||
}
|
||||
print "---" > filename
|
||||
print "hide: " h_hide > filename
|
||||
print "path: " h_path > filename
|
||||
print "titles: [\"" h_part "\",\"" h_chapter "\",\"" h_section "\"]" > filename
|
||||
print "index: [" idx "]" > filename
|
||||
print "---" > filename
|
||||
print heading > filename
|
||||
} else {
|
||||
print > filename
|
||||
# Start a new page
|
||||
if (n > 0) {
|
||||
close (filename)
|
||||
}
|
||||
n++
|
||||
|
||||
# Generate frontmatter contents
|
||||
name = gensub("^#+ (.*) <!-- .* -->$", "\\1", "1", $0)
|
||||
h_path = gensub("^#+ .* <!-- (.*) -->$", "\\1", "1", $0)
|
||||
heading = gensub ("^(#+ .*) <!-- .* -->$", "\\1", "1", $0)
|
||||
|
||||
# Is this page hidden?
|
||||
if (h_path ~ /\*$/) {
|
||||
h_path = substr(h_path, 1, length(h_path) - 1)
|
||||
h_hide = "true"
|
||||
} else {
|
||||
h_hide = "false"
|
||||
}
|
||||
|
||||
# Make filesystem path for writing the file
|
||||
file_path = h_path
|
||||
sub(/\/[^/]+$/, "", file_path)
|
||||
system("mkdir -p " filename_prefix file_path " 2>/dev/null")
|
||||
filename = filename_prefix h_path ".md"
|
||||
|
||||
print filename
|
||||
|
||||
switch ($0) {
|
||||
case /^# /:
|
||||
h_part = name
|
||||
h_chapter = ""
|
||||
h_section = ""
|
||||
h_part_no++
|
||||
h_chapter_no = 0
|
||||
idx = h_part_no
|
||||
break
|
||||
case /^## /:
|
||||
h_chapter = name
|
||||
h_section = ""
|
||||
h_chapter_no++
|
||||
h_section_no = 0
|
||||
idx = h_part_no "," h_chapter_no
|
||||
break
|
||||
case /^### /:
|
||||
h_section = name
|
||||
h_section_no++
|
||||
idx = h_part_no "," h_chapter_no "," h_section_no
|
||||
break
|
||||
default:
|
||||
print "Internal error"
|
||||
exit (1)
|
||||
}
|
||||
print "---" > filename
|
||||
print "hide: " h_hide > filename
|
||||
print "path: " h_path > filename
|
||||
print "titles: [\"" h_part "\",\"" h_chapter "\",\"" h_section "\"]" > filename
|
||||
print "index: [" idx "]" > filename
|
||||
print "sequence: " n > filename
|
||||
print "---" > filename
|
||||
print heading > filename
|
||||
|
||||
next
|
||||
}
|
||||
|
||||
# Rewrite image paths to reflect the directory hierarchy
|
||||
/<img src=\"markdown-pages.*\"/ {
|
||||
prefix = substr(h_path, 2)
|
||||
gsub(/[^/]*/, "..", prefix)
|
||||
sub(/src=\"markdown-pages/, "src=\"" prefix, $0)
|
||||
print > filename
|
||||
|
||||
next
|
||||
}
|
||||
|
||||
# Pass through everything else as-is
|
||||
{
|
||||
print > filename
|
||||
}
|
||||
|
||||
12
src/book.md
12
src/book.md
@@ -312,7 +312,7 @@ The calculation of rewards was overhauled in the Altair upgrade. The total rewar
|
||||
Note that the sum of five the weights is equal to `WEIGHT_DENOMINATOR`.
|
||||
|
||||
<div class="image">
|
||||
<img src="../../../images/weights.svg" style="width:50%" /><br />
|
||||
<img src="markdown-pages/images/weights.svg" style="width:50%" /><br />
|
||||
<span>The proportion of the total reward derived from each of the micro-rewards.</span>
|
||||
</div>
|
||||
|
||||
@@ -999,7 +999,7 @@ First, we pick a pivot index $p$. This is pseudorandomly chosen, based on the ro
|
||||
With this pivot, we then pick the mirror index $m_1$ halfway between $p$ and $0$. That is, $m_1 = p / 2$. (We will simplify by ignoring off-by-one rounding issues for the purposes of this explanation.)
|
||||
|
||||
<div class="image">
|
||||
<img src="../../../images/shuffling_0.svg" /><br />
|
||||
<img src="markdown-pages/images/shuffling_0.svg" /><br />
|
||||
<span>The pivot and the first mirror index.</span>
|
||||
</div>
|
||||
|
||||
@@ -1014,7 +1014,7 @@ If we do decide to swap, then we exchange the list element at $i$ with that at $
|
||||
We make the same swap-or-not decision for each index between $m_1$ and $p$.
|
||||
|
||||
<div class="image">
|
||||
<img src="../../../images/shuffling_1.svg" /><br />
|
||||
<img src="markdown-pages/images/shuffling_1.svg" /><br />
|
||||
<span>Swapping or not from the first mirror up to the pivot.</span>
|
||||
</div>
|
||||
|
||||
@@ -1025,7 +1025,7 @@ The decision as to whether to swap or not is based on hashing together the rando
|
||||
After considering all the indices $i$ from $m_1$ to $p$, mirroring in $m_1$, we now find a second mirror index at $m_2$, which is the point equidistant between $p$ and the end of the list: $m_2 = m_1 + n / 2$.
|
||||
|
||||
<div class="image">
|
||||
<img src="../../../images/shuffling_2.svg" /><br />
|
||||
<img src="markdown-pages/images/shuffling_2.svg" /><br />
|
||||
<span>The second mirror index.</span>
|
||||
</div>
|
||||
|
||||
@@ -1034,7 +1034,7 @@ After considering all the indices $i$ from $m_1$ to $p$, mirroring in $m_1$, we
|
||||
Finally, we repeat the swap-or-not process, considering all the points $j$ from the pivot, $p$ to the second mirror $m_2$. If we choose not to swap, we just move on. If we choose to swap then we exchange the element at $j$ with its image at $j'$ in the mirror index $m_2$. Here, $j' = m_2 + (m_2 - j)$.
|
||||
|
||||
<div class="image">
|
||||
<img src="../../../images/shuffling_3.svg" /><br />
|
||||
<img src="markdown-pages/images/shuffling_3.svg" /><br />
|
||||
<span>Swapping or not from the pivot to the second mirror.</span>
|
||||
</div>
|
||||
|
||||
@@ -1045,7 +1045,7 @@ At the end of the round, we have considered all the indices between $m_1$ and $m
|
||||
The next round begins by incrementing (or decrementing for a reverse shuffle) the round number, which gives us a new pivot index, and off we go again.
|
||||
|
||||
<div class="image">
|
||||
<img src="../../../images/shuffling_4.svg" /><br />
|
||||
<img src="markdown-pages/images/shuffling_4.svg" /><br />
|
||||
<span>The whole process running from one mirror to the other in a single round.</span>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user