Skip to content

Commit a78a2b6

Browse files
authored
Merge pull request #13 from jsdnhk/blog-enhance
intergrated auto scripts + fixes
2 parents 116f434 + eecbeb5 commit a78a2b6

17 files changed

Lines changed: 296 additions & 94 deletions

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.5.3

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ gem 'github-pages', group: :jekyll_plugins
55

66
group :development, :test do
77
gem 'html-proofer'
8-
gem 'parallel'
98
gem 'rake'
9+
gem 'parallel'
1010
gem 'rubocop'
1111
gem 'typhoeus'
1212
end

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 jsdnhk.github.io
3+
Copyright (c) 2020 David N
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Rakefile

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# frozen_string_literal: true
22

3-
require 'html-proofer'
43
require "rubygems"
4+
require "html-proofer"
55
require 'rake'
6+
67
require 'yaml'
78
require 'time'
89

@@ -11,45 +12,40 @@ COLLECTIONS = "collections"
1112
DIRS = {
1213
'layouts' => File.join(SOURCE, "_layouts"),
1314
'scripts' => File.join(SOURCE, "scripts"),
14-
'sites' => File.join(SOURCE, "_sites"),
15+
'pages' => File.join(SOURCE, "pages"),
16+
'site' => File.join(SOURCE, "_site"),
1517
'drafts' => File.join(SOURCE, COLLECTIONS, "_drafts"),
1618
'posts' => File.join(SOURCE, COLLECTIONS, "_posts"),
1719
'post_ext' => "md",
20+
'page_ext' => "md"
1821
}
1922

20-
# Path configuration helper
21-
module JB
22-
class Path
23-
SOURCE = "."
24-
Paths = {
25-
:layouts => "_layouts",
26-
:posts => "_posts"
27-
}
28-
29-
def self.base
30-
SOURCE
31-
end
32-
33-
# build a path relative to configured path settings.
34-
def self.build(path, opts = {})
35-
opts[:root] ||= SOURCE
36-
path = "#{opts[:root]}/#{Paths[path.to_sym]}/#{opts[:node]}".split("/")
37-
path.compact!
38-
File.__send__ :join, path
39-
end
40-
41-
end #Path
42-
end #JB
43-
44-
# Usage: rake post title="A Title" [date="2012-02-09"] [tags=[tag1,tag2]] [category="category"]
23+
def ask(message, valid_options)
24+
if valid_options
25+
answer = get_stdin("#{message}-->#{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
26+
else
27+
answer = get_stdin(message)
28+
end
29+
answer
30+
end
31+
32+
def get_stdin(message)
33+
print message
34+
STDIN.gets.chomp
35+
end
36+
37+
IS_COMMENT_ENABLE = true
38+
IS_DISPLAY_ENABLE = true
39+
# Usage: rake post [title="${title}"] [date="YYYY-MM-DD"] [tags=[${tag1},${tag2}...]] [category="${category}"]
4540
desc "Begin a new post in #{DIRS['posts']}"
4641
task :post do
4742
abort("rake aborted: '#{DIRS['posts']}' directory not found.") unless FileTest.directory?(DIRS['posts'])
4843
title = ENV["title"] || "new-post"
4944
tags = ENV["tags"] || "[]"
5045
category = ENV["category"] || ""
5146
category = "\"#{category.gsub(/-/,' ')}\"" if !category.empty?
52-
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
47+
# slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
48+
slug = "post"
5349
begin
5450
date = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d')
5551
rescue => e
@@ -58,44 +54,46 @@ task :post do
5854
end
5955
filename = File.join(DIRS['posts'], "#{date}-#{slug}.#{DIRS['post_ext']}")
6056
if File.exist?(filename)
61-
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
57+
abort("rake aborted!") unless ask("#{filename} already exists. Do you want to overwrite?", %w(y n)) == 'y'
6258
end
6359

6460
puts "Creating new post: #{filename}"
6561
open(filename, 'w') do |post|
6662
post.puts "---"
67-
post.puts "layout: post"
68-
post.puts "title: \"#{title.gsub(/-/,' ')}\""
69-
post.puts 'description: ""'
70-
post.puts "category: #{category}"
63+
# post.puts "layout: post"
64+
post.puts "title: \"#{title.strip}\""
7165
post.puts "tags: #{tags}"
66+
post.puts "category: \"#{category}\""
67+
# post.puts "display: #{IS_DISPLAY_ENABLE.to_s}"
68+
post.puts "comment: #{IS_COMMENT_ENABLE.to_s}"
7269
post.puts "---"
73-
post.puts "{% include JB/setup %}"
7470
end
7571
end # task :post
7672

77-
# Usage: rake page name="resume.html"
78-
# You can also specify a sub-directory path.
79-
# If you don't specify a file extention we create an index.html at the path specified
80-
desc "Create a new page."
73+
IS_TITLE_DISPLAY = true
74+
# Usage: rake page title="${pagename}"
75+
desc "Create a new page folder with index page"
8176
task :page do
82-
name = ENV["name"] || "new-page.md"
83-
filename = File.join(SOURCE, "#{name}")
84-
filename = File.join(filename, "index.html") if File.extname(filename) == ""
85-
title = File.basename(filename, File.extname(filename)).gsub(/[\W\_]/, " ").gsub(/\b\w/){$&.upcase}
77+
abort("rake aborted: the page title must be given.") unless ENV["title"] && !ENV["title"].empty?
78+
title = ENV["title"].strip
79+
dirname = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
80+
filename = File.join(DIRS['pages'], [dirname, "index.#{DIRS['page_ext']}"])
81+
# title = File.basename(filename, File.extname(filename)).gsub(/[\W\_]/, " ").gsub(/\b\w/){$&.upcase}
8682
if File.exist?(filename)
87-
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
83+
abort("rake aborted!") unless ask("#{filename} already exists. Do you want to overwrite?", %w(y n)) == 'y'
8884
end
8985

9086
mkdir_p File.dirname(filename)
91-
puts "Creating new page: #{filename}"
87+
puts "Creating new page folder: #{filename}"
9288
open(filename, 'w') do |post|
9389
post.puts "---"
9490
post.puts "layout: page"
9591
post.puts "title: \"#{title}\""
96-
post.puts 'description: ""'
92+
post.puts "title_image: \"\""
93+
post.puts "title_display: #{IS_TITLE_DISPLAY.to_s}"
94+
post.puts "footer_quote: \"\\\"quote\\\"---person\""
95+
post.puts "permalink: \"/#{dirname}/\""
9796
post.puts "---"
98-
post.puts "{% include JB/setup %}"
9997
end
10098
end # task :page
10199

@@ -106,24 +104,39 @@ task :reset do
106104
end
107105

108106
desc "Outputs any deprecation or configuration issues"
109-
task :reset do
110-
system 'jekyll doctor'
107+
task :doctor do
108+
system 'bundle exec jekyll doctor'
109+
end
110+
111+
desc "Perform Ruby programming syntax check"
112+
task :syncheck do
113+
system 'bundle exec rubocop -D -S'
111114
end
112115

113116
desc "Test the webpage in local"
114117
task :test do
115118
system 'bundle exec jekyll build'
116-
HTMLProofer.check_directory(DIRS['sites'], check_html: true).run
117-
end
118-
119-
desc "Update the site data"
120-
task :update do
121-
system "get-pages-latest-date.rb", chdir: DIRS['scripts']
119+
HTMLProofer.check_directory(DIRS['site'], check_html: true).run
122120
end
123121

124122
desc "Launch preview environment"
125123
task :preview do
126-
host_ip=`hostname -I | awk '{print $1;}'`
127-
system "jekyll serve -w -l --host #{host_ip} --port 4000"
124+
system "bundle exec jekyll serve -w -l --port 4000"
125+
end
126+
127+
desc "Reload the site info"
128+
task :reload do
129+
system "./get-pages-latest-date.rb", chdir: DIRS['scripts']
130+
end
131+
132+
desc "Push the current code to the master branch"
133+
task :cmpush => :reload do
134+
abort("rake aborted!") unless ask("Sure to commit all the change to remote?", %w(y n)) == 'y'
135+
system "./git-commit-push.sh", chdir: DIRS['scripts']
128136
end
129137

138+
desc "Push the current code to the master branch"
139+
task :verpush => :reload do
140+
abort("rake aborted!") unless ask("Sure to push the new version to remote?", %w(y n)) == 'y'
141+
system "./git-version-push.sh", chdir: DIRS['scripts']
142+
end

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ defaults:
7676
type: "posts"
7777
values:
7878
layout: post
79+
tags: []
80+
category: ""
7981
display: true
8082
comment: false
8183
- scope:

_data/links.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
- https://opensource.microsoft.com
2929
- https://opensource.com
3030
- https://redhatofficial.github.io
31-
- http://apache.org
31+
- https://apache.org
3232

3333
- type: "Search For Answer"
3434
icon: "categories/system-help.png"

_data/pages_latest.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
- name: blog
3-
mtime: '20200202'
3+
mtime: '20200224'
44
- name: debug
55
mtime: '20200202'
66
- name: links
7-
mtime: '20200219'
7+
mtime: '20200225'
88
- name: quotes
9-
mtime: '20200220'
9+
mtime: '20200221'
1010
- name: resume
1111
mtime: '20200202'

_data/quotes/einstein.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
- group: Religion
33
quotes:
44
- God is subtle but he is not malicious.
5-
- God always takes the simplest way.
65
- Coincidence is God’s way of remaining anonymous.
6+
- God always takes the simplest way.
77
- When the solution is simple, God is answering.
88
- Before God we are all equally wise – and equally foolish.
99
- What really interests me is whether God had any choice in the creation of the world.

assets/js/sidebar/logo.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ const title_weather = 'Current Weather: ';
99
const index_selected_json = Number(new Date().getMonth()) % saints_json.length;
1010
const filepath_selected_json = `${saints_folder}/${saints_json[index_selected_json]}`;
1111

12+
let obj_selected_json = null;
13+
1214
function showAlertLogo() {
13-
getQuoteMessage();
15+
if (!obj_selected_json) {
16+
doAjaxGet(filepath_selected_json).then((json) => {getQuoteMessage(json);});
17+
} else {
18+
getQuoteMessage();
19+
}
1420
}
1521

1622
function showLogoMessage(quote_message) {
@@ -22,19 +28,16 @@ function showLogoMessage(quote_message) {
2228
alert(show_message);
2329
}
2430

25-
function getQuoteMessage(){
31+
function getQuoteMessage(json){
2632
var quote_message = '';
27-
doAjaxGet(filepath_selected_json).then((json) => {
28-
// random index fetch
29-
var index_select_quote = getRandomQuoteIndex(json.count);
30-
// text handling
31-
if (index_select_quote != null) {
32-
var text_select_quote = json.results[index_select_quote].quoteText.toString().trim();
33-
var author_select_quote = json.results[index_select_quote].quoteAuthor.toString().trim();
34-
quote_message = text_select_quote + '\n\n' + author_select_quote;
35-
}
36-
showLogoMessage(quote_message);
37-
});
33+
if (json) { obj_selected_json = json; }
34+
var index_select_quote = getRandomQuoteIndex(obj_selected_json.count);
35+
if (index_select_quote != null) {
36+
var text_select_quote = obj_selected_json.results[index_select_quote].quoteText.toString().trim();
37+
var author_select_quote = obj_selected_json.results[index_select_quote].quoteAuthor.toString().trim();
38+
quote_message = text_select_quote + '\n\n' + author_select_quote;
39+
}
40+
showLogoMessage(quote_message);
3841
}
3942

4043
var count_quotes_total = 0;
@@ -60,7 +63,11 @@ function getRandomQuoteIndex(count_total){
6063
function getPrintedQuoteMessage(quote_message){
6164
let str_printed = '';
6265
if(quote_message) {
63-
str_printed = `(${count_quotes_total - count_quotes_read}) ${title_quote}`;
66+
if (count_quotes_total - count_quotes_read > 0) {
67+
str_printed = `(${count_quotes_total - count_quotes_read}) ${title_quote}`;
68+
} else {
69+
str_printed = `${title_quote}`;
70+
}
6471
str_printed += '\n\n' + quote_message;
6572
} else {
6673
str_printed = title_quote_complete;
@@ -89,4 +96,4 @@ async function doAjaxGet(ajaxurl) {
8996
return data;
9097
}
9198
throw new Error(response.status);
92-
}
99+
}

assets/saints/confucius.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
"quoteAuthor": "Confucius",
1010
"quoteText": "The more you know yourself, the more you forgive yourself."
1111
},
12-
{
13-
"quoteText": "Silence is a true friend who never betrays.",
14-
"quoteAuthor": "Confucius"
15-
},
1612
{
1713
"quoteAuthor": "Confucius",
1814
"quoteText": "Wherever you go, go with all your heart."
@@ -85,10 +81,6 @@
8581
"quoteText": "I want you to be everything that's you, deep at the center of your being.",
8682
"quoteAuthor": "Confucius"
8783
},
88-
{
89-
"quoteText": "To be wronged is nothing unless you continue to remember it.",
90-
"quoteAuthor": "Confucius"
91-
},
9284
{
9385
"quoteText": "Silence is the true friend that never betrays.",
9486
"quoteAuthor": "Confucius"
@@ -99,7 +91,7 @@
9991
},
10092
{
10193
"quoteAuthor": "Confucius",
102-
"quoteText": "The Superior Man is aware of Righteousness, the inferior man is aware of advantage."
94+
"quoteText": "The superior man is aware of righteousness, the inferior man is aware of advantage."
10395
},
10496
{
10597
"quoteText": "Everything has beauty, but not everyone sees it.",
@@ -129,10 +121,6 @@
129121
"quoteText": "If you look into your own heart, and you find nothing wrong there, what is there to worry about? What is there to fear?",
130122
"quoteAuthor": "Confucius"
131123
},
132-
{
133-
"quoteAuthor": "Confucius",
134-
"quoteText": "Learning without reflection is a waste, reflection without learning is dangerous."
135-
},
136124
{
137125
"quoteText": "To give ones self earnestly to the duties due to men, and, while respecting spiritual beings, to keep aloof from them, may be called wisdom.",
138126
"quoteAuthor": "Confucius"

0 commit comments

Comments
 (0)