forked from kadalu/kadalu.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-site.sh
98 lines (73 loc) · 3.23 KB
/
generate-site.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
set -e
ROOT_DIR=$(ruby -e 'puts File.expand_path(".")')
function version_checkout
{
local project_name=$1
local version=$2
cd "${ROOT_DIR}/tmprepos/${project_name}" && git checkout -b v${version} ${version}
}
function prepare_versioned_docs
{
local projects_yaml_file=$1
local project_name=$2
local project_repo=$3
local docs_dir=$4
local version=$5
mkdir -p "${ROOT_DIR}/content/docs/${project_name}"
project_dir="${ROOT_DIR}/content/docs/${project_name}"
version_dir="${project_dir}/${version}"
# Copy the docs directory to respective version directory
cp -r "${ROOT_DIR}/tmprepos/${project_name}/${docs_dir}" "${version_dir}"
# Create empty versions.html file in project root dir
echo > "${project_dir}/versions.html"
# Create empty redirect.html file
echo > "${version_dir}/redirect.html"
# Replace Relative links, *.adoc links
ruby ${ROOT_DIR}/scripts/process_files.rb "${version_dir}" ${project_name} ${project_repo} ${version}
}
function build_site
{
cd ${ROOT_DIR} && bundle install
cd ${ROOT_DIR} && npm install
cd ${ROOT_DIR} && npm run prod:css
cd ${ROOT_DIR} && bundle exec nanoc compile --env prod
}
function main
{
local projects_yaml_file=$(ruby -e "puts File.expand_path(\"$1\")")
mkdir -p "${ROOT_DIR}/tmprepos"
# Copy projects.yml to root dir
cp "${projects_yaml_file}" "${ROOT_DIR}/content/docs/"
ruby ${ROOT_DIR}/scripts/projects.rb $projects_yaml_file | while read project_line
do
local project_name=$(echo $project_line | awk -F# '{print $1}')
local project_repo=$(echo $project_line | awk -F# '{print $2}')
local docs_dir=$(echo $project_line | awk -F# '{print $3}')
# Delete the Project Repo if exists
rm -rf "${ROOT_DIR}/tmprepos/${project_name}"
# Clear the directory before copying the doc directory from repo
rm -rf "${ROOT_DIR}/content/docs/${project_name}"
# Clone the Project Repo and fetch all tags
git clone --depth 1 ${project_repo} ${ROOT_DIR}/tmprepos/${project_name}
cd ${ROOT_DIR}/tmprepos/${project_name} && git fetch --depth=1 origin +refs/tags/*:refs/tags/*
# For each required version checkout and prepare the docs
ruby ${ROOT_DIR}/scripts/versions.rb $projects_yaml_file $project_name | while read version
do
version_checkout $project_name $version
prepare_versioned_docs $projects_yaml_file $project_name $project_repo $docs_dir $version
done
# Checkout the Latest alias version again and setup as required
latest_alias=$(ruby ${ROOT_DIR}/scripts/latest_alias.rb $projects_yaml_file $project_name)
cd "${ROOT_DIR}/tmprepos/${project_name}" && git checkout v${latest_alias}
prepare_versioned_docs $projects_yaml_file $project_name $project_repo $docs_dir "latest"
done
# Clone the Rfcs Repo
git clone --depth 1 https://github.com/kadalu/rfcs.git ${ROOT_DIR}/tmprepos/rfcs
# Copy the rfcs/text directory
cp -r "${ROOT_DIR}/tmprepos/rfcs/text" "${ROOT_DIR}/content/rfcs"
cp -r "${ROOT_DIR}/tmprepos/rfcs/README.adoc" "${ROOT_DIR}/content/rfcs/index.adoc"
build_site
}
echo "Project directory: ${ROOT_DIR}"
main $1