This is an automated email from the ASF dual-hosted git repository.

anthony pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-website.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1de171b9 move and prepare files for content folder
1de171b9 is described below

commit 1de171b910983628e1b7e19dbeac0a3bb09dbab0
Author: Anthony Grasso <[email protected]>
AuthorDate: Sat Apr 2 15:41:01 2022 +1100

    move and prepare files for content folder
    
    * Added logic to move generated website and in-tree docs to content folder
    * Added logic to remove hardcoded and missing domains from links
    * Added logging functionality
    
    patch by Anthony Grasso; reviewed by Michael Semb Wever for CASSANDRA-17374
---
 site-content/Dockerfile           |   2 +
 site-content/docker-entrypoint.sh | 128 ++++++++++++++++++++++++++++++++++----
 2 files changed, 119 insertions(+), 11 deletions(-)

diff --git a/site-content/Dockerfile b/site-content/Dockerfile
index c38a2d1c..2993c5be 100644
--- a/site-content/Dockerfile
+++ b/site-content/Dockerfile
@@ -103,6 +103,8 @@ ENV 
ANTORA_UI_BUNDLE_URL="https://github.com/apache/cassandra-website/raw/trunk/
 
 ENV CASSANDRA_DOWNLOADS_URL="https://downloads.apache.org/cassandra/";
 
+ENV LOG_LEVEL="INFO"
+
 EXPOSE 5151/tcp
 
 # Run as build user from here
diff --git a/site-content/docker-entrypoint.sh 
b/site-content/docker-entrypoint.sh
index e2f60f43..584fe0f0 100755
--- a/site-content/docker-entrypoint.sh
+++ b/site-content/docker-entrypoint.sh
@@ -26,10 +26,10 @@ generate_cassandra_versioned_docs() {
   # a local copy as some of the pages need to be generated from the source 
code.
   if [ "$(find "${CASSANDRA_SOURCE_DIR}" -mindepth 1 -type f | wc -l)" -eq 0 ]
   then
-    echo "Cloning ${ANTORA_CONTENT_SOURCES_CASSANDRA_URL} to working directory"
+    log_message "INFO" "Cloning ${ANTORA_CONTENT_SOURCES_CASSANDRA_URL} to 
working directory"
     git clone "${ANTORA_CONTENT_SOURCES_CASSANDRA_URL}" 
"${CASSANDRA_WORKING_DIR}"
   else
-    echo "Copying ${CASSANDRA_SOURCE_DIR} to working directory"
+    log_message "INFO" "Copying ${CASSANDRA_SOURCE_DIR} to working directory"
     cp -a "${CASSANDRA_SOURCE_DIR}/." "${CASSANDRA_WORKING_DIR}/"
   fi
 
@@ -51,12 +51,12 @@ generate_cassandra_versioned_docs() {
 
   for version in ${GENERATE_CASSANDRA_VERSIONS}
   do
-    echo "Checking out '${version}'"
+    log_message "INFO" "Checking out '${version}'"
     pushd "${CASSANDRA_WORKING_DIR}" > /dev/null
     git clean -xdff
     git checkout "${version}"
 
-    echo "Building JAR files"
+    log_message "INFO" "Building JAR files"
     # Nodetool docs are autogenerated, and that needs nodetool to be built. 
However, before we can build nodetool we
     # need to select the correct Java version
     local doc_version=""
@@ -80,7 +80,7 @@ generate_cassandra_versioned_docs() {
     sudo update-alternatives --set java ${java_version}
     sudo update-alternatives --set javac ${javac_version}
 
-    echo "Using Java compiler version $(javac -version) to compile Cassandra 
JARs"
+    log_message "INFO" "Using Java compiler version $(javac -version) to 
compile Cassandra JARs"
     ant realclean
     ant "${ant_cmd_options}" gen-asciidoc
     popd > /dev/null
@@ -93,7 +93,7 @@ generate_cassandra_versioned_docs() {
       # generating the HTML.
       sed -i '/^doc/d' .gitignore
       git add .
-      git commit -m "Automated commit: Generated nodetool and configuration 
documentation for version ${doc_version}." || echo "No new changes to commit."
+      git commit -m "Automated commit: Generated nodetool and configuration 
documentation for version ${doc_version}." || log_message "INFO" "No new 
changes to commit."
     fi
     popd > /dev/null
   done
@@ -180,7 +180,7 @@ generate_site_yaml() {
     fi
   done
 
-  echo "Building site.yaml"
+  log_message "INFO" "Building site.yaml"
   rm -f site.yaml
   python3 ./bin/site_yaml_generator.py \
     -s "$(generate_json \
@@ -196,14 +196,87 @@ generate_site_yaml() {
 
 render_site_content_to_html() {
   pushd "${CASSANDRA_WEBSITE_DIR}/site-content" > /dev/null
-  echo "Building the site HTML content."
+  log_message "INFO" "Building the site HTML content."
   antora --generator antora-site-generator-lunr site.yaml
-  echo "Rendering complete!"
+  log_message "INFO" "Rendering complete!"
   popd > /dev/null
 }
 
+
+prepare_site_html_for_publication() {
+  pushd "${CASSANDRA_WEBSITE_DIR}" > /dev/null
+
+  # copy everything to content/ directory
+  log_message "INFO" "Moving site HTML to content/"
+  mkdir -p content/doc
+  cp -r site-content/build/html/* content/
+
+  # remove hardcoded domain name, and empty domain names first before we 
duplicate and documentation
+  content_files_to_change=($(grep -rl 'https://cassandra.apache.org/' 
content/))
+  log_message "INFO" "Removing hardcoded domain names in 
${#content_files_to_change[*]} files"
+  for content_file in ${content_files_to_change[*]}
+  do
+    log_message "DEBUG" "Processing file ${content_file}"
+    # sed automatically uses the character following the 's' as a delimiter.
+    # In this case we will use the ',' so we can avoid the need to escape the 
'/' characters
+    sed -i 's,https://cassandra.apache.org/,/,g' ${content_file}
+  done
+
+  content_files_to_change=($(grep -rl 'href="//' content/))
+  log_message "INFO" "Removing empty domain names in 
${#content_files_to_change[*]} files"
+  for content_file in ${content_files_to_change[*]}
+  do
+    log_message "DEBUG" "Processing file ${content_file}"
+    sed -i 's,href="//,href="/,g' ${content_file}
+  done
+
+  # move around the in-tree docs if generated
+  if [ "${COMMAND_GENERATE_DOCS}" = "run" ]
+  then
+    log_message "INFO" "Moving versioned documentation HTML to content/doc"
+    move_intree_document_directories "3.11" "3.11.11" "3.11.12"
+    move_intree_document_directories "4.0" "4.0.0" "4.0.1" "4.0.2" "4.0.3" 
"stable"
+    move_intree_document_directories "trunk" "4.1" "latest"
+  fi
+
+  popd > /dev/null
+}
+
+
+move_intree_document_directories() {
+    local source_doc_dir="$1"
+    shift
+    local target_doc_versions=("$@")
+
+    local source_base_dir="content/Cassandra"
+    local target_base_dir="content/doc"
+
+    if [ ${#target_doc_versions[*]} -eq 0 ] || [ "${source_doc_dir}" = "" ]
+    then
+      return
+    fi
+
+    if [ -d "${source_base_dir}/${source_doc_dir}" ]
+    then
+      for cas_ver in ${target_doc_versions[*]}
+      do
+        rm -fR ${target_base_dir}/${cas_ver}
+        cp -r ${source_base_dir}/${source_doc_dir} 
${target_base_dir}/${cas_ver}
+      done
+      rm -fR ${target_base_dir}/${source_doc_dir}
+      mv ${source_base_dir}/${source_doc_dir} ${target_base_dir}/
+    fi
+
+    # Check if our source directory is empty and if it is clean it up.
+    # Otherwise, leave it as is so we can see if we have missed a version.
+    if [ -z "$(ls -A ${source_base_dir})" ]
+    then
+      rmdir "${source_base_dir}"
+    fi
+}
+
 run_preview_mode() {
-  echo "Entering preview mode!"
+  log_message "INFO" "Entering preview mode!"
 
   export -f render_site_content_to_html
 
@@ -241,10 +314,41 @@ run_preview_mode() {
 }
 
 
+log_level_str_to_int() {
+  local log_level_int
+  case $1 in
+    "OFF")
+      log_level_int=0
+    ;;
+    "ERROR")
+      log_level_int=1
+    ;;
+    "WARN")
+      log_level_int=2
+    ;;
+    "INFO")
+      log_level_int=3
+    ;;
+    "DEBUG"|"*")
+      log_level_int=4
+    ;;
+  esac
+  echo ${log_level_int}
+}
+
+
+log_message() {
+  if [ ${LOG_LEVEL_INT} -ne 0  ] && [ $(log_level_str_to_int $1) -le 
${LOG_LEVEL_INT} ]
+  then
+    echo "container: $1: $2"
+  fi
+}
+
 # ============ MAIN ============
 
 GENERATE_CASSANDRA_VERSIONS=$(sed 's/^[[:space:]]]*//' <<< 
"${ANTORA_CONTENT_SOURCES_CASSANDRA_BRANCHES} 
${ANTORA_CONTENT_SOURCES_CASSANDRA_TAGS}")
 export GENERATE_CASSANDRA_VERSIONS
+export LOG_LEVEL_INT=$(log_level_str_to_int "${LOG_LEVEL}")
 
 ANTORA_CONTENT_SOURCE_REPOSITORIES=(
   CASSANDRA_WEBSITE
@@ -269,7 +373,7 @@ do
       COMMAND_PREVIEW="run"
     ;;
     *)
-      echo "Skipping unrecognised command '$1'."
+      log_message "WARN" "Skipping unrecognised command '$1'."
     ;;
   esac
 
@@ -293,6 +397,8 @@ then
   export DOCSEARCH_INDEX_VERSION=latest
 
   render_site_content_to_html
+
+  prepare_site_html_for_publication
 fi
 
 if [ "${COMMAND_PREVIEW}" = "run" ]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to