-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/elmsln/issues/issues/1721
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { stdResponse, invalidRequest } from "../../../utilities/requestHelpers.js"; | ||
|
||
// vercel to slice our data into views that we can remix at will | ||
export default async function handler(req, res) { | ||
// cache for a day | ||
let options = { | ||
cache: 60 * 60 * 24 | ||
}; | ||
// process.env.HAX_STATS has our stats compiled by our staging system | ||
let data = await fetch(process.env.HAX_STATS).then((res) => { | ||
return res.json() | ||
}); | ||
if (data) { | ||
res = stdResponse(res, data || [], options); | ||
} | ||
else { | ||
res = invalidRequest(res, 'data from stats failed to load'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
# script for stat generation for iam | ||
# Initialize variables to hold total counts | ||
total_items=0 | ||
site_counts=() | ||
# Initialize variables to hold folder counts and site counts | ||
site_count=0 | ||
user_count=0 | ||
|
||
# Loop through user directories to calculate valid users and sites | ||
for user_dir in /var/www/iam/users/*; do | ||
if [ -d "$user_dir/sites" ]; then | ||
user_folders=$(find $user_dir/sites/* -maxdepth 0 -type d ! -type l 2>/dev/null | wc -l) | ||
if [ "$user_folders" -gt 1 ]; then | ||
user_name="$(basename "$user_dir")" | ||
# Exclude certain users from the count | ||
if [ "$user_name" != "bto108" ] && [ "$user_name" != "bto5009" ] && [ "$user_name" != "elms" ]; then | ||
user_count=$((user_count + 1)) | ||
# Find all site.json files and process them | ||
for sitepath in $(find $user_dir/sites/* -maxdepth 0 -type d ! -type l 2>/dev/null); do | ||
# sites.json sanity | ||
if [ -f "$sitepath/site.json" ]; then | ||
site_name="$(basename "$sitepath")" | ||
site_items=$(jq '.items | length' "$sitepath/site.json") # Using jq to parse JSON and count items | ||
# only count things that have more than 5 pages | ||
# ignore these things from a demo early on | ||
if [ "$site_name" != "covid19" ] && [ "$site_name" != "test" ] && [ "$site_name" != "test3" ] && [ "$site_name" != "testing" ] && [ "$site_name" != "coronavirus" ] && [ "$site_name" != "covid-19" ]; then | ||
if [ $site_items -gt 5 ]; then | ||
site_count=$((site_count + 1)) | ||
total_items=$(($total_items + site_items)) | ||
siteshort="$user_name/$site_name" | ||
site_counts+=("$siteshort:$site_items") | ||
fi | ||
fi | ||
fi | ||
done | ||
fi | ||
fi | ||
fi | ||
done | ||
|
||
IFS=$'\n' sorted_site_counts=($(sort -k2 -nr <<<"${site_counts[*]}")) | ||
unset IFS | ||
|
||
# Construct JSON object for stats | ||
stats_json="{ \"overall\": { \"site_count\": $site_count, \"user_count\": $user_count, \"total_pages\": $total_items }, \"site_counts\": {" | ||
json_blob="" | ||
|
||
# Construct JSON entries for individual site counts | ||
for entry in "${sorted_site_counts[@]}"; do | ||
site_file="${entry%:*}" | ||
items_count="${entry#*:}" | ||
stats_json+=" \"$site_file\": $items_count," | ||
done | ||
|
||
stats_json="${stats_json%,}" # Remove trailing comma | ||
stats_json+=" } }" # Close JSON object | ||
|
||
# Write stats JSON to file | ||
echo "$stats_json" > /var/www/html/stats/stats.json |
2c05022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
lrnwebcomponents – ./
lrnwebcomponents-git-master-elmsln.vercel.app
haxapi.vercel.app
lrnwebcomponents.vercel.app
lrnwebcomponents-elmsln.vercel.app