New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fragments collection #19

Merged
merged 1 commit into from Oct 3, 2017
Jump to file or symbol
Failed to load files and symbols.
+120 −3
Diff settings

Always

Just for now

Copy path View file
@@ -35,9 +35,14 @@ plugins:
# permalink: /:categories/:year/:month/:day/:title
permalink: /:year/:month/:day/:title/
# Themes are encouraged to use these universal variables
# so be sure to set them if your theme uses them.
#
# https://jekyllrb.com/docs/collections/
# Not everything is a post or a page.
# Collections allow you to define a new type of document that behave like Pages or Posts do normally,
# but also have their own unique properties and namespace.
collections:
fragments:
output: true

This comment has been minimized.

@bf4

bf4 Oct 3, 2017

Owner

each file in _fragments is copied over

title: Benjamin Fleischer
tagline: My space
author:
@@ -0,0 +1,99 @@
---
layout: post

This comment has been minimized.

@bf4

bf4 Oct 3, 2017

Owner

A file in _fragments is basically a post

This comment has been minimized.

title: "Download a S3-served website whose index listing is exposed"
published: true
---
{% include JB/setup %}
Suppose there's a website you'd like to mirror locally that you can tell is served via an
AWS S3 website. Here's a way to download it if the S3 index is exposed.
If the site is [http://flaws.cloud/](http://flaws.cloud/), and it is served by an S3
bucket named `flaws.cloud`, then you can visit the S3 bucket at
[http://flaws.cloud.s3.amazonaws.com/](http://flaws.cloud.s3.amazonaws.com/).
1) Create a new directory, let's call it `flaws-cloud`, and `cd` into it.
2) Create a script `run.sh`:
```bash
cat << 'EOF' > run.sh
#!/usr/bin/env bash
BUCKET_NAME="flaws.cloud" exec ./download-s3-site.sh
EOF
chmod u+x run.sh
```
and make it executable `chmod u+x run.sh`.
3) In the same directory, paste the script below as '`download-s3-site.sh`' and make it executable.
4) You can then download the site by running `./run.sh`.
I separated the configuration (run.sh) from the actual script (download-s3-site.sh) just to make it more
easily reusable for me.
```bash
cat << 'EOF' > download-s3-site.sh
#!/usr/bin/env bash
set -eou pipefail
if [ -z "${BUCKET_NAME:-}" ]; then echo "[FATAL] BUCKET_NAME not set" >&2 ; exit 1; fi
OVERWRITE="false"
DEBUG="${DEBUG:-false}"
info() { echo "[INFO] $*" >&2 ; }
debug() { if [ "$DEBUG" = "true" ]; then echo "[DEBUG] $*" >&2 ; fi ; }
download() {
local remote_filename local_filename
remote_filename="$1"
local_filename="$2"
if [ "$OVERWRITE" = "true" ] || [ ! -e "${local_filename}" ] ; then
curl \
--insecure \
--silent --show-error \
--location \
--create-dirs \
"https://${BUCKET_NAME}.s3.amazonaws.com${remote_filename}" \
--output "${local_filename}"
else
debug "Already downloaded ${local_filename}"
fi
}
download_file() {
local remote_filename
remote_filename="$1"
download "/${remote_filename}" "${remote_filename}"
}
download_index() {
download "" index.xml
}
download_files() {
ruby -rrexml/document -e 'REXML::Document.new(STDIN.read).root.each_element("//Key") {|elem| puts elem.text }' \
< index.xml \
| while read -r remote_filename; do
download_file "$remote_filename"
done
}
main() {
download_index
download_files
}
main
EOF
chmod u+x download-s3-site.sh
./run.sh
```
Copy path View file
No changes.
Copy path View file
@@ -0,0 +1,13 @@
---
title: Fragments

This comment has been minimized.

@bf4

bf4 Oct 3, 2017

Owner

Adds a /fragments page which lists all the fragments.

header: Fragments
group: navigation

This comment has been minimized.

@bf4

bf4 Oct 3, 2017

Owner

Adds this page to the nav group on the top

screen shot 2017-10-03 at 2 32 15 pm

---
{% include JB/setup %}
<h2>All Fragments</h2>
<ul>
{% assign pages_list = site.fragments %}

This comment has been minimized.

@bf4

bf4 Oct 3, 2017

Owner

the fragments collection is accessible in site. There's also a site.collections, but I don't want that

{% include JB/pages_list %}

This comment has been minimized.

@bf4

bf4 Oct 3, 2017

Owner

I'm using the jekyll bootstrap page iterator here. I might want to change this to posts ¯\_(ツ)_/¯

</ul>
ProTip! Use n and p to navigate between commits in a pull request.