Skip to content
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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions _config.yml
Expand Up @@ -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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each file in _fragments is copied over


title: Benjamin Fleischer
tagline: My space
author:
Expand Down
99 changes: 99 additions & 0 deletions _fragments/download_an_s3_site_with_exposed_index.md
@@ -0,0 +1,99 @@
---
layout: post
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A file in _fragments is basically a post

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

```
Empty file removed _thoughts/git_in_gemspec.md
Empty file.
13 changes: 13 additions & 0 deletions fragments.md
@@ -0,0 +1,13 @@
---
title: Fragments
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a /fragments page which lists all the fragments.

header: Fragments
group: navigation
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 %}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

{% include JB/pages_list %}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

</ul>