mirror

werc .tpl file to mirror github raw content

Mirrored from GitHub

git clone https://github.com/christc4/mirror.git

Jump to: README.md index.tpl list-curl.sh


README.md

# mirror

this is a werc .tpl page to mirror RAW content from your github repo, using the provided list-curl.sh script

GitHub repos (via REST API) return structured JSON describing each file/folder at a path, including things like file name, size, type, download URL, etc.

If you just want the names of all files in the root directory, the script list-curl.sh returns that

dependencies 

- curl: to fetch the data
- jq: to filter out just the file names

see <https://bauherren.ovh/dump/kode/christos/werc/tpl/mirror/> for an example

index.tpl

<!-- EXAMPLE -->

<h1>mirror</h1>

<p>werc .tpl file to mirror github raw content

<p>Mirrored from <a href=//github.com/christc4/mirror>GitHub</a>

<p><pre>git clone https://github.com/christc4/mirror.git</pre>

<p>Jump to:
% apilink=https://api.github.com/repos/christc4/mirror
% gitlink=https://raw.githubusercontent.com/christc4/mirror/refs/heads/main/
%	files=`{list-curl $apilink}
%		for(match in $files){
<a href=#%($"match%)>%($"match%)</a>
% }
<hr>
%	files=`{list-curl $apilink}
%		for(match in $files){
<h2><a name=%($"match%)>%($"match%)</a></h2>
<pre>
%			curl -L  $gitlink/$match | escape_html
</pre>
%		}


list-curl.sh

#!/bin/sh

if [ -z "$1" ]; then
  echo "Usage: $0 <github_repo_api_url>"
  exit 1
fi

curl -s "$1/contents/?ref=main" | jq -r '.[].name'