1
0
Fork 0

docs(documentation.md): Use START and END tag

Instead of explicitely listing all sections
This commit is contained in:
Matthieu Dumont 2015-12-18 17:45:15 +01:00 committed by Sylvain UTARD
parent 33c1841ad3
commit a3cf2cd2b4
2 changed files with 14 additions and 17 deletions

View file

@ -3,7 +3,6 @@ layout: page
title: Documentation
permalink: /documentation/
---
# Usage
```html
@ -19,13 +18,18 @@ documentationSearch({
});
```
# Examples
- http://eslint.org/
- https://bootstrap.algolia.com/
- https://reactjs.algolia.com/
- https://babeljs.algolia.com/
# How do I get an `apiKey` and `indexName`?
Send us [an email](mailto:docsearch@algolia.com) with the url of
the documentation website you would like to add search to.
# How does it work?
The JavaScript library is a wrapper on top of our

View file

@ -1,26 +1,21 @@
#!/usr/bin/env bash
#!/bin/sh
set -o nounset
set -o errexit
readonly SOURCE=README.md
readonly OUTPUT=docs/documentation.md
readonly SECTIONS=(
'Usage'
'How do I get an `apiKey` and `indexName`?'
'How does it work?'
)
readonly START_TAG="<!-- START documentation.md -->"
readonly END_TAG="<!-- END documentation.md -->"
function escape_regex {
echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g'
echo "$@" | sed -e 's/[]\/\!$*.^|[]/\\&/g'
}
function extract {
local section=${1}
echo
sed -n "/^#\s*$(escape_regex $section)\s*$/,/^#[^#]/p" \
| head -n -1
sed -n "/^\s*$(escape_regex $START_TAG)\s*$/,/^\s*$(escape_regex $END_TAG)\s*$/p" \
| sed '$d' \
| sed -n '2,$p'
}
function main {
@ -32,9 +27,7 @@ function main {
echo "permalink: /documentation/" >> $OUTPUT
echo "---" >> $OUTPUT
for section in "${SECTIONS[@]}"; do
cat $SOURCE | extract "$section" >> $OUTPUT
done
cat $SOURCE | extract >> $OUTPUT
}
main