Skip to content

Commit

Permalink
Upgrade for the native protocols spec page
Browse files Browse the repository at this point in the history
  • Loading branch information
tengu-alt committed Aug 30, 2024
1 parent dddece2 commit fc53c8c
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 14 deletions.
3 changes: 3 additions & 0 deletions site-content/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ EXPOSE 5151/tcp
USER ${BUILD_USER}
WORKDIR ${BUILD_DIR}
COPY docker-entrypoint.sh /usr/local/bin/

COPY process-native-protocol-specs-in-docker.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]

# Possible commands are listed below. The entrypoint will accept any combination of these commands.
Expand Down
3 changes: 3 additions & 0 deletions site-content/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ render_site_content_to_html() {


prepare_site_html_for_publication() {
log_message "INFO" "Processing native protocols spec page"
sudo /usr/local/bin/process-native-protocol-specs-in-docker.sh

pushd "${CASSANDRA_WEBSITE_DIR}" > /dev/null

# copy everything to content/ directory
Expand Down
41 changes: 41 additions & 0 deletions site-content/process-native-protocol-specs-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status.
set -e

# Variables
GO_VERSION="1.20.6"
GO_TAR="go${GO_VERSION}.linux-amd64.tar.gz"
GITHUB_REPO_PARSER="https://github.com/martin-sucha/cqlprotodoc.git" # Replace with the actual parser repo URL
PARSER_DIR="/home/build/cqlprotodoc"
WEBSITE_DIR="/home/build/cassandra-website"

# Step 0: Download and install Go
echo "Downloading Go $GO_VERSION..."
wget https://golang.org/dl/$GO_TAR

echo "Installing Go..."
tar -C /usr/local -xzf $GO_TAR

# Set Go environment variables
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go

# Step 1: Clone the GitHub repo with the Go parser
echo "Cloning the cqlprotodoc repository..."
git clone "$GITHUB_REPO_PARSER" "$PARSER_DIR"

# Step 2: Build the parser
echo "Building the cqlprotodoc..."
cd "$PARSER_DIR"
go build -o cqlprotodoc

# Step 3: Process the spec files using the parser
echo "Processing the .spec files..."
"$PARSER_DIR"/cqlprotodoc "$WEBSITE_DIR/site-content/source/modules/ROOT/examples/TEXT" "$WEBSITE_DIR/site-content/build/html/_"

# Step 4: Cleanup - Remove the Cassandra and parser directories
echo "Cleaning up..."
rm -rf "$PARSER_DIR" /usr/local/go $GO_TAR

echo "Script completed successfully."
84 changes: 72 additions & 12 deletions site-content/source/modules/ROOT/pages/native_protocol.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,81 @@

== Native Protocol Version 3

[source, plaintext]
----
include::example$TEXT/native_protocol_v3.spec[Version 3]
----
[source, js]
++++
<div id="contentv3" class="doc-container"></div>
<iframe id="iframev3" src="native_protocol_v3.html" style="display:none;"></iframe>
++++

== Native Protocol Version 4

[source, plaintext]
----
include::example$TEXT/native_protocol_v4.spec[Version 4]
----
[source, js]
++++
<div id="contentv4" class="doc-container"></div>
<iframe id="iframev4" src="native_protocol_v4.html" style="display:none;"></iframe>
++++

== Native Protocol Version 5

[source, plaintext]
----
include::example$TEXT/native_protocol_v5.spec[Version 5]
----
[source, js]
++++
<div id="contentv5" class="doc-container"></div>
<iframe id="iframev5" src="native_protocol_v5.html" style="display:none;"></iframe>
++++

[source, js]
++++
<script>
function copyBodyContent(iframeId, contentId) {
var iframe = document.getElementById(iframeId);
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
var navElement = iframeDocument.querySelector('nav.top');
if (navElement) {
navElement.remove();
}
var preElements = iframeDocument.querySelectorAll('pre');
preElements.forEach(function(preElement) {
if (!preElement.textContent.trim()) {
preElement.remove();
}
});
var h1Elements = iframeDocument.querySelectorAll('h1');
h1Elements.forEach(function(h1Element) {
h1Element.remove();
});
var bodyContent = iframeDocument.body.innerHTML;
document.getElementById(contentId).innerHTML = bodyContent;
}
function setNavigation() {
var containers = document.querySelectorAll('.doc-container');
containers.forEach(function (container) {
var navLinks = container.querySelectorAll('nav a, pre a');
navLinks.forEach(function (link) {
link.addEventListener('click', function (event) {
event.preventDefault();
var section = link.getAttribute('href').replace("#",'');
var targetSection = container.querySelector('h2[id="' + section + '"]') || container.querySelector('h3[id="' + section + '"]') || container.querySelector('h4[id="' + section + '"]') || container.querySelector('h5[id="' + section + '"]');
if (targetSection) {
targetSection.scrollIntoView({ behavior: 'smooth' });
}
});
});
});
}
window.onload = function() {
copyBodyContent('iframev3', 'contentv3');
copyBodyContent('iframev4', 'contentv4');
copyBodyContent('iframev5', 'contentv5');
setNavigation()
}
</script>
++++
4 changes: 2 additions & 2 deletions site-ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:18.04
FROM ubuntu:22.04
#
# Set up non-root user, 'build', with default uid:gid
# This allows passing --build-arg to use localhost username, and uid:gid:
Expand All @@ -15,7 +15,7 @@ FROM ubuntu:18.04
ARG BUILD_USER_ARG="build"
ARG UID_ARG=1000
ARG GID_ARG=1000
ARG NODE_VERSION_ARG="v12.16.2"
ARG NODE_VERSION_ARG="v20.16.0"

ENV BUILD_USER=${BUILD_USER_ARG}

Expand Down

0 comments on commit fc53c8c

Please sign in to comment.