mirror of https://github.com/Qiskit/qiskit.org.git
Update to the new textbook TOC format (#126)
* Update to the new textbook TOC format
This commit is contained in:
parent
641d836177
commit
d23dfb5a69
|
@ -1 +1,38 @@
|
|||
## Table of Contents
|
||||
## Table of Contents
|
||||
### Chapter 0. Prerequisites
|
||||
- Python and Jupyter Notebooks
|
||||
- Qiskit
|
||||
- Linear Algebra
|
||||
### Chapter 1. Quantum States and Qubits
|
||||
- Introduction
|
||||
- The Atoms of Computation
|
||||
- The Unique Properties of Qubits
|
||||
- Writing Down Qubit States
|
||||
- Pauli Matrices and the Bloch Sphere
|
||||
- States for Many Qubits
|
||||
### Chapter 2. Single Qubits and Multi-Qubits gates
|
||||
- Introduction
|
||||
- Quantum Gates
|
||||
- Fun with Matrices
|
||||
- The Standard Gate Set
|
||||
- Proving Universality
|
||||
- Basic Circuit Identities
|
||||
### Chapter 3. Quantum Algorithms
|
||||
- Quantum Teleportation
|
||||
- Deutsch-Josza Algorithm
|
||||
- Bernstein-Vazirani Algorithm
|
||||
- Simon's Algorithm
|
||||
- Quantum Fourier Transform
|
||||
- Quantum Phase Estimation
|
||||
- Grover's Algorithm
|
||||
### Chapter 4. Quantum Algorithms for Applications
|
||||
- Simulating Molecules using VQE
|
||||
- Solving Satisfiability Problems using Grover's Algorithm
|
||||
### Chapter 5. Investigating Quantum Hardware Using Qiskit
|
||||
- Calibrating Qubits with OpenPulse
|
||||
- Introduction to Quantum Error Correction using Repetition Codes
|
||||
- Measurement Error Mitigation
|
||||
- Randomized Benchmarking
|
||||
- Measuring Quantum Volume
|
||||
### Chapter 6. Implementations of Recent Quantum Algorithms
|
||||
- Variational Quantum Linear Solver
|
||||
|
|
|
@ -12,5 +12,5 @@ export default function generateTextbookToc (indexPath: string, tocPath: string)
|
|||
const indexContent = fs.readFileSync(indexPath, 'utf8')
|
||||
const toc = extractToc(indexContent)
|
||||
const mdTocLines = formatTocLines(toc)
|
||||
fs.writeFileSync(tocPath, mdTocLines.join('\n'))
|
||||
fs.writeFileSync(tocPath, mdTocLines.join('\n') + '\n')
|
||||
}
|
||||
|
|
|
@ -2,23 +2,34 @@ type TocType = Array<[string, string[]]>
|
|||
|
||||
export { extractToc, formatTocLines, TocType }
|
||||
|
||||
function extractToc (indexContent: string): TocType {
|
||||
// Chapter titles are of form `Chapter X. Chapter title<`.
|
||||
const allChapters = (indexContent.match(/Chapter\s+\d+\.\s+[^<]+/g) || [])
|
||||
.map(entry => entry.trim())
|
||||
// Topic titles are of form `X.Y <a ...>Topic Title<`
|
||||
const allTopics = (indexContent.match(/(\d+.\d+\s+)<a[^>]+([^<]+)/g) || [])
|
||||
.map(entry => entry.replace(/<a[^>]+>/, '').trim())
|
||||
// Chapter titles are of form `X. Chapter title<`.
|
||||
const chapterRegex = />\s+\d+\.\s+[^<]+/g
|
||||
|
||||
// Topic titles are of form `X.Y Topic Title<`
|
||||
const topicRegex = />\s+\d+.\d+\s+[^<]+/g
|
||||
|
||||
function extractToc (indexContent: string): TocType {
|
||||
const allChapters = getFromContent(chapterRegex, indexContent)
|
||||
const allTopics = getFromContent(topicRegex, indexContent)
|
||||
return allChapters.reduce<TocType>((output, title, index) => {
|
||||
const chapters = getTopics(index, allTopics)
|
||||
output.push([title, chapters])
|
||||
return output
|
||||
}, [])
|
||||
|
||||
function getFromContent (regex: RegExp, content: string): string[] {
|
||||
return (content.match(regex) || []).map(clean)
|
||||
}
|
||||
|
||||
function getTopics (index: number, allTopics: string[]) {
|
||||
return allTopics.filter(topic => topic.startsWith(`${index}.`))
|
||||
}
|
||||
|
||||
function clean (str: string) {
|
||||
// Remove leading character '>' and white space.
|
||||
// Normalize blank space into one single space.
|
||||
return str.replace(/>\s+/, '').replace(/\s+/g, ' ').trim()
|
||||
}
|
||||
}
|
||||
|
||||
function formatTocLines (toc: TocType, header: string = 'Table of Contents'): string[] {
|
||||
|
@ -37,7 +48,7 @@ function formatTocLines (toc: TocType, header: string = 'Table of Contents'): st
|
|||
}
|
||||
|
||||
function formatTitle (title: string): string {
|
||||
return `### ${title}`
|
||||
return `### Chapter ${title}`
|
||||
}
|
||||
|
||||
function formatChapters (chapters: string[]): string[] {
|
||||
|
|
|
@ -153,7 +153,7 @@ export default {
|
|||
build: {
|
||||
before () {
|
||||
generateTextbookToc(
|
||||
'./static/textbook/index.html',
|
||||
'./static/textbook/preface.html',
|
||||
'./content/education/textbook-toc.md'
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,18 +1,76 @@
|
|||
import { extractToc, formatTocLines, TocType } from '~/hooks/textbook-toc-utils'
|
||||
|
||||
const sampleHTML = `<p><strong>Chapter 0. Title 0</strong><br /></p>
|
||||
<p> 0.0 <a href="./ch-prerequisites/python-and-jupyter-notebooks.html">Topic 0.0</a><br />
|
||||
0.1 <a href="./ch-prerequisites/qiskit.html">Topic 0.1</a><br />
|
||||
<p><strong>Chapter 1. Title 1</strong><br /></p>
|
||||
<p> 1.0 <a href="./ch-states/introduction.html">Topic 1.0</a><br />
|
||||
1.1 <a href="./ch-states/atoms-computation.html">Topic 1.1</a><br />`
|
||||
const sampleHTML = `<li class="c-sidebar__chapter">
|
||||
<a class="c-sidebar__entry "
|
||||
href=".html"
|
||||
>
|
||||
|
||||
0.
|
||||
|
||||
Title 0
|
||||
</a>
|
||||
<ul class="c-sidebar__sections ">
|
||||
<li class="c-sidebar__section">
|
||||
<a class="c-sidebar__entry "
|
||||
href="/textbook/ch-prerequisites/python-and-jupyter-notebooks.html"
|
||||
>
|
||||
|
||||
0.0
|
||||
|
||||
Topic 0.0
|
||||
</a>
|
||||
</li>
|
||||
<li class="c-sidebar__section">
|
||||
<a class="c-sidebar__entry "
|
||||
href="/textbook/ch-prerequisites/qiskit.html"
|
||||
>
|
||||
|
||||
0.1
|
||||
|
||||
Topic 0.1
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="c-sidebar__chapter">
|
||||
<a class="c-sidebar__entry "
|
||||
href=".html"
|
||||
>
|
||||
|
||||
1.
|
||||
|
||||
Title 1
|
||||
</a>
|
||||
<ul class="c-sidebar__sections ">
|
||||
<li class="c-sidebar__section">
|
||||
<a class="c-sidebar__entry "
|
||||
href="/textbook/ch-states/introduction.html"
|
||||
>
|
||||
|
||||
1.0
|
||||
|
||||
Topic 1.0
|
||||
</a>
|
||||
</li>
|
||||
<li class="c-sidebar__section">
|
||||
<a class="c-sidebar__entry "
|
||||
href="/textbook/ch-states/atoms-computation.html"
|
||||
>
|
||||
|
||||
1.1
|
||||
|
||||
Topic 1.1
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>`
|
||||
|
||||
const expectedToc: TocType = [
|
||||
['Chapter 0. Title 0', [
|
||||
['0. Title 0', [
|
||||
'0.0 Topic 0.0',
|
||||
'0.1 Topic 0.1'
|
||||
]],
|
||||
['Chapter 1. Title 1', [
|
||||
['1. Title 1', [
|
||||
'1.0 Topic 1.0',
|
||||
'1.1 Topic 1.1'
|
||||
]]
|
||||
|
|
Loading…
Reference in New Issue