Last active
June 6, 2019 18:59
-
-
Save callaginn/a0fad2cf95838511cb78722a6bd11792 to your computer and use it in GitHub Desktop.
Download docs and code for all Shopify themes for further analysis. Use with caution; rate limits and latest version NOT tested.
This file contains hidden or 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
| # SHOPIFY THEME EXPORTER | |
| # This script downloads docs / code for ALL Shopify themes for further analysis. | |
| # For example, you can search the downloaded code for framework-specific classes | |
| # like "col-md-", "btn-outline", etc. | |
| # NOTE: Use with caution or you'll be rate limited! Latest version not tested. | |
| baseUrl="https://themes.shopify.com" | |
| destPath="$HOME/desktop/themes-shopify" | |
| # Grab Pagination Urls | |
| pageUrls=( | |
| "/themes?page=1" | |
| $(curl "${baseUrl}/themes/" | grep "pagination" | grep -Eo "/themes[a-zA-Z0-9./?=_-]*" | sort -u) | |
| ) | |
| # Cycle through Shopify's pagination | |
| for pageUrl in "${pageUrls[@]}"; do | |
| echo "${pageUrl}" | |
| # Search for Theme Doc Urls | |
| # Example: /themes/empire/styles/supply | |
| for url in $(curl "$pageUrl" | grep -Eo "/themes/[a-zA-Z0-9./?=_-]*"); do | |
| theme=$(echo "${url}" | awk -F / '{print $3}') | |
| style=$(echo "${url}" | awk -F / '{print $NF}') | |
| docFile="${destPath}/$theme/$style.html" | |
| prevFile="${destPath}/$theme/previews/$style.html" | |
| codeFile="${destPath}/$theme/code/$style.html" | |
| echo "Downloading ${theme} ${style} theme..." | |
| curl "${baseUrl}${url}" --create-dirs -o "${docFile}" | |
| # Read exported docFiles to find demo urls | |
| demoUrl=$(cat "${docFile}" | grep "View demo" | grep -Eo "[a-zA-Z0-9./?=_-]*/preview" | uniq) | |
| echo "> $demoUrl" | |
| curl "${baseUrl}${demoUrl}" >| "${prevFile}" | |
| # Grab iframe URL from preview | |
| iframeUrl=$(cat "${prevFile}" | grep "PreviewFrame" | grep -Eo "https://[a-zA-Z0-9./?=_-]*") | |
| echo ">> $iframeUrl" | |
| curl "$iframeUrl" >| "${codeFile}" | |
| done | |
| done | |
| # Open code editor for analysis | |
| atom "${destPath}/$theme/code" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment