Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/docsify/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "docsify",
"id": "docsify",
"version": "0.1.1",
"version": "0.1.2",
"description": "Automatically serves ./docs workspace directory via 'docsify serve' in the background.",
"options": {
"port": {
Expand Down
3 changes: 3 additions & 0 deletions src/docsify/fallback/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Fake Site

> An awesome fake site test.
22 changes: 22 additions & 0 deletions src/docsify/fallback/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fake Site</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
name: 'fakesite',
repo: 'fakerepo'
}
</script>
<!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
</body>
</html>
58 changes: 15 additions & 43 deletions src/docsify/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,19 @@
set -e

DOCSIFY_SERVE_PATH="/usr/local/bin/docsify-serve"
DOCSIFY_FALLBACK_PATH="/usr/local/share/docsify-serve/fallback"

DOCS_PATH=${DOCS_PATH:-docs}

echo "Activating feature 'docsify-cli'..."

npm install -g docsify-cli

# The fallback/default index.html file to use when the documents directory does
# not exist.
DEFAULT_INDEX_HTML=$(cat <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fake Site</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
name: 'fakesite',
repo: 'fakerepo'
}
</script>
<!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
</body>
</html>
EOF
)

# The fallback/default README.md file to use when the documents directory does
# not exist.
DEFAULT_README_MD=$(cat <<EOF
# Fake Site
mkdir -p "${DOCSIFY_FALLBACK_PATH}"
cp fallback/index.html fallback/README.md "${DOCSIFY_FALLBACK_PATH}"

> An awesome fake site test.
EOF
)

tee "${DOCSIFY_SERVE_PATH}" > /dev/null \
<< EOF
#!/usr/bin/env sh
cat <<EOF >"${DOCSIFY_SERVE_PATH}"
#!/usr/bin/env bash

# we need to explicitly "activate" (the current) node here, as otherwise
# devcontainers using our feature and also setting their remoteEnv PATH will
Expand All @@ -58,17 +24,23 @@ nvm use node

mkdir -p "${DOCS_PATH}"
if [ ! -f "${DOCS_PATH}/index.html" ]; then
echo "${DEFAULT_INDEX_HTML}" > "${DOCS_PATH}/index.html"
echo "${DEFAULT_README_MD}" > "${DOCS_PATH}/README.md"
cp ${DOCSIFY_FALLBACK_PATH}/* "${DOCS_PATH}"
fi

nohup bash -c "\
# since this script is going to be executed as this feature's
# "postStartCommand" there is an important catch here: it is run via
# "docker exec -it ...". Please notice the absence of "-d" as this is a
# synchronous operation. Just using "nohup" as shown in several cases is
# a bad idea: when postStartCommand finishes, it tears down the nohup.
# Thus, use setsid(1) (https://man7.org/linux/man-pages/man1/setsid.1.html)
# to run the docsify serve node process in a new session.
setsid --fork bash -c "\
docsify serve \
-p=${PORT} \
-P=${LIVERELOAD_PORT} \
--no-open \
${DOCS_PATH} \
&" >/tmp/nohup-docsify.log 2>&1
>/tmp/nohup-docsify.log 2>&1"
EOF

chmod 0755 "${DOCSIFY_SERVE_PATH}"