Skip to content

Instantly share code, notes, and snippets.

@diogorusso
Last active October 28, 2018 00:35
Show Gist options
  • Save diogorusso/4e1077eb454ea8d656dcc51e1f5d61bd to your computer and use it in GitHub Desktop.
Save diogorusso/4e1077eb454ea8d656dcc51e1f5d61bd to your computer and use it in GitHub Desktop.

Jekyll

  • What's Jekyll
  • Rake Generate Posts from Json
  • Behance Plugin
  • Theme generation (shell)

What's Jekyll

Jekyll is a simple, blog-aware, static site generator. It takes a template directory containing raw text files in various formats, runs it through a converter (like Markdown) and our Liquid renderer, and spits out a complete, ready-to-publish static website suitable for serving with your favorite web server. Jekyll also happens to be the engine behind GitHub Pages, which means you can use Jekyll to host your project’s page, blog, or website from GitHub’s servers for free.

require File.expand_path('../project', __FILE__)
require File.expand_path('../user', __FILE__)
require File.expand_path('../wips', __FILE__)
require File.expand_path('../collections', __FILE__)
require File.expand_path('../fields', __FILE__)
require File.expand_path('../creatives_to_follow', __FILE__)
require 'faraday'
require 'faraday_middleware'
# Public: Methods handled by the Client connection.
module Behance
class Client
API_URL = "http://www.behance.net/v2/"
include Behance::Client::Project
include Behance::Client::User
include Behance::Client::Wips
include Behance::Client::Collections
include Behance::Client::Fields
include Behance::Client::CreativesToFollow
attr_accessor :access_token, :connection
# Public: Initialize a client for API requests.
#
# options - The Hash with options required by Behance:
# :access_token - Behance API token.
#
# Examples
#
# @client = Behance::Client.new(access_token: "aKlie12MCJa5")
#
# Returns a Faraday instance object.
def initialize(options={})
@access_token = options[:access_token]
@connection = Faraday.new(url: Behance::Client::API_URL) do |b|
b.adapter Faraday.default_adapter
b.use FaradayMiddleware::ParseJson
end
end
# Public: Makes a http request to the API.
#
# path - A String that represents the endpoint path.
# options - Hash of parameters to pass along.
#
# Examples
#
# request("users/1")
# request("projects", page: 2)
#
# Returns a response body from the API.
def request(path, options={})
response = @connection.get do |req|
req.url path
req.params[:api_key] = @access_token
req.params[:page] = 4
options.each do |key, val|
req.params[key] = val
end
end
response.body
end
end
end
IFS=$'\r\n' GLOBIGNORE='*' command eval 'configSources=($(cat ./_scripts/sh/_config-sources.txt))'
for (( i = 0 ; i < ${#configSources[@]} ; i++))
do
echo "Element [$i]: ${configSources[$i]}"
echo "🐙 \033[1;34m qual default url para ${configSources[$i]}? \033[0m"
read siteUrl
echo "🐙 \033[1;34m qual baseUrl para ${configSources[$i]}? \033[0m"
read baseUrl
echo "
#DEV
url: '$siteUrl' # the base hostname & protocol for your site
baseurl: '$baseUrl' # only for github, gulp baseurl set in config_${configSources[$i]}.yml
" >> _config/_site/${configSources[$i]}.yml
echo "🐙 \033[1;34m ${configSources[$i]} YML!!! \033[0m"
done
echo "🐙 \033[1;34m Criando Gemfile para $theme \033[0m"
echo "
#selected theme: $theme
source 'https://rubygems.org'
# ruby RUBY_VERSION
gem 'jekyll'
gem '$theme', :path => './_theme/$theme/'
# If you want to use GitHub Pages, remove the ''gem jekyll'' above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem 'github-pages', group: :jekyll_plugins
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'jekyll-sitemap'
gem 'jekyll-feed'
gem 'jekyll-paginate'
#hologram styleguide generator
gem 'hologram'
" >> Gemfile
echo "🐙 \033[1;34m Gemfile done!!! \033[0m"
echo "🐙 \033[1;34m Criando Gemspec para $theme \033[0m"
# cria o arquivo inicial para ser editado
echo "
Gem::Specification.new do |spec|
spec.name = '$theme'
" >> ./_theme/$theme/$theme.gemspec
# append o resto arquivo em separado para evitar bugs de caracteres
# nesse caso regexp nao funciona na conversão
cat >> ./_theme/$theme/$theme.gemspec <<- 'EOF'
spec.version = '0.0.0'
spec.authors = ['Diogo Russo']
spec.email = ['hello_diogorusso@gmail.com']
spec.summary = %q{Oh Sorte!!!!!.}
spec.description = 'Diogo from BRazil, nice to meet you you hope you hace fun, hey ho!!!!'
spec.homepage = 'https://hello.diogorusso.com'
spec.license = 'MIT'
spec.metadata["plugin_type"] = "theme"
spec.files = `git ls-files -z`.split("\x0").select do |f|
f.match(%r{^(assets|_(includes|layouts|sass)/|(LICENSE|README)((\.(txt|md|markdown)|$)))}i)
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.add_runtime_dependency "jekyll", "~> 3.3"
spec.add_development_dependency "bundler", "~> 1.12"
spec.add_development_dependency "rake", "~> 10.0"
end
EOF
# converte ASCII para UTF8
file -I ./_theme/$theme/$theme.gemspec
echo "encoding "src/_theme/$theme/$theme.gemspec" ("us-ascii") to utf-8"
build_post()
{
for row in $json; do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
rake gen:post DIST=$dist TITLE=$(_jq '.title') D=$(_jq '.date') TAGS=$(_jq '.tags') TAGLINE=$(_jq '.tagline') LINK=$(_jq '.link') COVER=$(_jq '.cover')
echo $(_jq '.title')
done
}
build_post_design()
{
json=$(cat ./_data/projects-design.json | jq -r '.[]| @base64' )
dist="../design/_posts"
rm -rf ./design/_posts/*.*
build_post
}
build_post_art()
{
json=$(cat ./_data/projects-art.json | jq -r '.[]| @base64' )
dist="../artwork/_posts"
rm -rf ./artwork/_posts/*.*
build_post
}
PS3='Please enter your choice: '
options=("Build Work" "Build All Projects" "Build Design Projects" "Build Art Projects" "Delete All Projects" "Exit")
select opt in "${options[@]}"
do
case $opt in
"Build Work")
sh ./_scripts/build-work.sh
;;
"Build All Projects")
build_post_art
build_post_design
;;
"Build Design Projects")
build_post_design
;;
"Build Art Projects")
build_post_art
;;
"Delete All Projects")
rm -rf ./art/_posts/*.*
rm -rf ./design/_posts/*.*
;;
"Exit")
break
;;
*) echo "invalid option $REPLY"
;;
esac
done
namespace :gen do
desc "Create an empty post in /_posts, e.g., rake gen:post TITLE='This is a Sample Title'"
task :post do
err_mes = "Must specificy post TITLE, e.g., rake gen:post TITLE='This is a Sample Title'"
raise err_mes unless ENV.has_key?('TITLE')
post_title = ENV['TITLE'].camelize
post_category = ENV['CATEGORY'].camelize
post_tagline = ENV['TAGLINE'].camelize
post_description = ENV['DESCRIPTION']
post_link = ENV['LINK']
post_cover = ENV['COVER']
date = ENV['D'] || Date.today.to_s
base_filename = ENV['FN'] || ENV['TITLE'].downcase.gsub(/\s+/, "-")
post_filename = date + "_" + base_filename + ".markdown"
post_dist=ENV['DIST']
post_path = APP_ROOT.join(post_dist, post_filename)
file_exists_mes = "ERROR: post file '#{post_path}' already exists"
tags = ENV['TAGS'] || "software engineering"
tag_str = ""
tags = tags.split(",").each { |tag| tag_str << '- ' + tag + "\n" }
tag_str.chomp!
raise file_exists_mes if File.exist?(post_path)
puts "Created #{post_path}"
File.open(post_path, 'w+') do |f|
f.write(<<-EOF.strip_heredoc)
---
layout: post_simple
category: "#{post_category}"
title: "#{post_title}"
link: "#{post_link}"
cover: "#{post_cover}"
date: #{date}
author: "Diogo Russo"
tagline: "#{post_tagline}"
description: "#{post_description}"
tags:
#{tag_str}
---
Sample content goes here. This is the first paragraph that you should replace with your content for #{post_title}.
Now, go write something awesome...
EOF
end
end
end
[
{
"title":"",
"internal": "",
"client": "",
"category":"",
"date":"2017-01-02",
"tags":"",
"tagline":"post tagline",
"link":"wwww",
"cover":".jpg",
"description":""
}
]
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'rubygems'
require 'uri'
require 'pathname'
APP_ROOT = Pathname.new(File.expand_path('../', __FILE__))
APP_NAME = APP_ROOT.basename.to_s
require ::File.expand_path('../_scripts/rake-env.rb', __FILE__)
require 'rake'
require 'active_support'
require 'active_support/core_ext'
require 'active_support/deprecation'
load './_scripts/post.rake'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment