|
18 | 18 | # Branch name to create |
19 | 19 | NEW_BRANCH="gh-pages-${BRANCH_SUFFIX}" |
20 | 20 |
|
| 21 | +# Get the current docs version from config |
| 22 | +DOCS_VERSION=$(node -p "require('js-yaml').load(require('fs').readFileSync('config.yml', 'utf8')).docs_version") |
| 23 | + |
21 | 24 | # Function to print colored messages |
22 | 25 | print_success() { |
23 | 26 | echo -e "${GREEN}✓ $1${NC}" |
|
89 | 92 | print_success "Pulled latest changes from origin/gh-pages" |
90 | 93 |
|
91 | 94 | # Step 4: Create a new branch for the update |
| 95 | +print_info "Checking if branch ${NEW_BRANCH} exists and deleting it if it does…" |
| 96 | +if git show-ref --verify --quiet refs/heads/${NEW_BRANCH}; then |
| 97 | + execute "git branch -D ${NEW_BRANCH}" |
| 98 | +else |
| 99 | + print_info "Branch ${NEW_BRANCH} does not exist, proceeding with creation…" |
| 100 | +fi |
92 | 101 | print_info "Creating new branch ${NEW_BRANCH}…" |
93 | 102 | execute "git checkout -b ${NEW_BRANCH}" |
94 | 103 |
|
95 | | -# Step 5: Move root files |
96 | | -print_info "Moving root files from temporary location…" |
97 | | -ROOT_FILES=("404.html" "CNAME" "apple-touch-icon.png" "favicon.ico" "index.html" "robots.txt" "sitemap-0.xml" "sitemap-index.xml" "sw.js") |
98 | | -for file in "${ROOT_FILES[@]}"; do |
99 | | - if [ -f "/tmp/_site/$file" ]; then |
100 | | - execute "mv /tmp/_site/$file ." |
101 | | - else |
102 | | - print_warning "File /tmp/_site/$file not found. Skipping." |
103 | | - fi |
104 | | -done |
105 | | - |
106 | | -# Step 6: Move directories with cleanup |
107 | | -print_info "Moving directories from temporary location…" |
108 | | -DIRS=("about" "components" "docsref" "examples" "getting-started" "migration") |
109 | | -for dir in "${DIRS[@]}"; do |
110 | | - if [ -d "/tmp/_site/$dir" ]; then |
111 | | - if [ -d "$dir" ]; then |
112 | | - execute "rm -rf $dir" |
113 | | - fi |
114 | | - execute "mv /tmp/_site/$dir ." |
115 | | - else |
116 | | - print_warning "Directory /tmp/_site/$dir not found. Skipping." |
117 | | - fi |
118 | | -done |
119 | | - |
120 | | -# Step 7: Handle special doc directories |
121 | | -print_info "Handling special documentation directories…" |
122 | | -SPECIAL_DOCS=("docs/getting-started" "docs/versions") |
123 | | -for dir in "${SPECIAL_DOCS[@]}"; do |
124 | | - if [ -d "/tmp/_site/$dir" ]; then |
125 | | - if [ -d "$dir" ]; then |
126 | | - execute "rm -rf $dir" |
127 | | - fi |
128 | | - # Make sure parent directory exists |
129 | | - parent_dir=$(dirname "$dir") |
130 | | - mkdir -p "$parent_dir" |
131 | | - execute "mv /tmp/_site/$dir $parent_dir/" |
132 | | - else |
133 | | - print_warning "Directory /tmp/_site/$dir not found. Skipping." |
134 | | - fi |
135 | | -done |
| 104 | +# Step 5: Move all root-level files from Astro build |
| 105 | +find /tmp/_site -maxdepth 1 -type f -exec mv {} . \; |
136 | 106 |
|
137 | | -# Step 8: Move docs index.html |
138 | | -if [ -f "/tmp/_site/docs/index.html" ]; then |
139 | | - execute "mv /tmp/_site/docs/index.html docs/index.html" |
140 | | -else |
141 | | - print_warning "File /tmp/_site/docs/index.html not found. Skipping." |
142 | | -fi |
| 107 | +# Step 6: Move all top-level directories except 'docs' (which needs special handling) |
| 108 | +find /tmp/_site -maxdepth 1 -type d ! -name "_site" ! -name "docs" -exec sh -c 'dir=$(basename "$1"); rm -rf "$dir"; mv "$1" .' _ {} \; |
143 | 109 |
|
144 | | -# Step 9: Handle docs/5.3 |
145 | | -if [ -d "/tmp/_site/docs/5.3" ]; then |
146 | | - if [ -d "docs/5.3" ]; then |
147 | | - execute "rm -rf docs/5.3" |
| 110 | +# Step 7: Handle docs directory specially |
| 111 | +if [ -d "/tmp/_site/docs" ]; then |
| 112 | + # Replace only the current version's docs |
| 113 | + if [ -d "docs/$DOCS_VERSION" ]; then |
| 114 | + rm -rf "docs/$DOCS_VERSION" |
148 | 115 | fi |
149 | | - execute "mv /tmp/_site/docs/5.3 docs/" |
150 | | -else |
151 | | - print_warning "Directory /tmp/_site/docs/5.3 not found. Skipping." |
| 116 | + mv "/tmp/_site/docs/$DOCS_VERSION" "docs/" |
| 117 | + |
| 118 | + # Handle docs root files |
| 119 | + find /tmp/_site/docs -maxdepth 1 -type f -exec mv {} docs/ \; |
| 120 | + |
| 121 | + # Handle special docs directories (getting-started, versions) |
| 122 | + for special_dir in getting-started versions; do |
| 123 | + if [ -d "/tmp/_site/docs/$special_dir" ]; then |
| 124 | + rm -rf "docs/$special_dir" |
| 125 | + mv "/tmp/_site/docs/$special_dir" "docs/" |
| 126 | + fi |
| 127 | + done |
152 | 128 | fi |
153 | 129 |
|
154 | 130 | # Clean up remaining files in /tmp/_site if any |
|
0 commit comments