updated books.pl to have variables for file names; changed the js variable names; updated index.html to match changes
This commit is contained in:
parent
ccde468e88
commit
697aff0b8d
51
books.pl
51
books.pl
@ -5,8 +5,8 @@ use 5.010;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use File::Slurp; # https://metacpan.org/pod/File::Slurp
|
use File::Slurp; # https://metacpan.org/pod/File::Slurp
|
||||||
use JSON;
|
use JSON; # https://metacpan.org/pod/JSON
|
||||||
use Time::Piece;
|
use Time::Piece; # https://perldoc.perl.org/Time::Piece
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
@ -19,15 +19,24 @@ use DateTime;
|
|||||||
# splitting them up into "pages" for easier display
|
# splitting them up into "pages" for easier display
|
||||||
#
|
#
|
||||||
# license GPLv3.0 https://www.gnu.org/licenses/gpl-3.0.en.html
|
# license GPLv3.0 https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||||
# Code repository:
|
# Code repository: https://code.jacobhaddon.com/jake/dbpc
|
||||||
#
|
|
||||||
# Written by Jacob Haddon https://jacobhaddon.com
|
# Written by Jacob Haddon https://jacobhaddon.com
|
||||||
#
|
#
|
||||||
# This uses File::Slurp - https://metacpan.org/pod/File::Slurp
|
# This uses
|
||||||
|
# * File::Slurp - https://metacpan.org/pod/File::Slurp
|
||||||
|
# * JSON - https://metacpan.org/pod/JSON
|
||||||
|
#
|
||||||
# Texts are from Project Gutenburg - https://www.gutenberg.org/
|
# Texts are from Project Gutenburg - https://www.gutenberg.org/
|
||||||
#
|
#
|
||||||
###################################
|
###################################
|
||||||
|
|
||||||
|
# While these have json formatting, they are JS files
|
||||||
|
my $complete_books_js = "complete_books.js";
|
||||||
|
my $book_pages_js = "book_pages2.js";
|
||||||
|
|
||||||
|
# number of lines in a page
|
||||||
|
my $number_of_lines = 31;
|
||||||
|
|
||||||
my $json = new JSON;
|
my $json = new JSON;
|
||||||
|
|
||||||
# my $date = localtime->strftime('%Y-%m-%d');
|
# my $date = localtime->strftime('%Y-%m-%d');
|
||||||
@ -38,19 +47,22 @@ my @books = (
|
|||||||
title => "Wuthering Heights",
|
title => "Wuthering Heights",
|
||||||
author => "Emily Bronte",
|
author => "Emily Bronte",
|
||||||
url => "https://www.gutenberg.org/ebooks/768",
|
url => "https://www.gutenberg.org/ebooks/768",
|
||||||
file => "books/wutheringheights.txt"
|
file => "books/wutheringheights.txt",
|
||||||
|
chapter_marker => "CHAPTER"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title => "Jane Eyre",
|
title => "Jane Eyre",
|
||||||
author => "Charlotte Bronte",
|
author => "Charlotte Bronte",
|
||||||
url => "https://www.gutenberg.org/ebooks/1260",
|
url => "https://www.gutenberg.org/ebooks/1260",
|
||||||
file => "books/janeeyre.txt"
|
file => "books/janeeyre.txt",
|
||||||
|
chapter_marker => "CHAPTER"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title => "Agnes Grey",
|
title => "Agnes Grey",
|
||||||
author => "Anne Bronte",
|
author => "Anne Bronte",
|
||||||
url => "https://www.gutenberg.org/ebooks/767",
|
url => "https://www.gutenberg.org/ebooks/767",
|
||||||
file => "books/agnesgrey.txt"
|
file => "books/agnesgrey.txt",
|
||||||
|
chapter_marker => "CHAPTER"
|
||||||
}
|
}
|
||||||
); # books hash
|
); # books hash
|
||||||
|
|
||||||
@ -69,12 +81,11 @@ foreach (@books) {
|
|||||||
# read in a whole file into a scalar
|
# read in a whole file into a scalar
|
||||||
my $book = read_file($books[$k]{'file'});
|
my $book = read_file($books[$k]{'file'});
|
||||||
|
|
||||||
my @chapters = split('\nCHAPTER', $book);
|
my @chapters = split('\n' . $books[$k]{'chapter_marker'}, $book);
|
||||||
my $test = @chapters;
|
my $test = @chapters;
|
||||||
# print($test);
|
# print($test);
|
||||||
|
|
||||||
# number of lines in a page
|
|
||||||
my $number_of_lines = 31;
|
|
||||||
|
|
||||||
my $j = 0;
|
my $j = 0;
|
||||||
my @page_text;
|
my @page_text;
|
||||||
@ -141,10 +152,10 @@ $books[$k]{'pages'} = \@page_text;
|
|||||||
# my $json_text = encode_json(\%books);
|
# my $json_text = encode_json(\%books);
|
||||||
my $json_text = $json->pretty->encode( \@books );
|
my $json_text = $json->pretty->encode( \@books );
|
||||||
|
|
||||||
my $js_text = "let book = " . $json_text;
|
my $js_text = "let books = " . $json_text;
|
||||||
|
|
||||||
# write the file
|
# write the file
|
||||||
open(FH, '>', "test4.js") or die $!;
|
open(FH, '>', $complete_books_js) or die $!;
|
||||||
print FH $js_text;
|
print FH $js_text;
|
||||||
close(FH);
|
close(FH);
|
||||||
|
|
||||||
@ -182,12 +193,18 @@ for ( my $l; $l < 365; $l++){
|
|||||||
# my $new_test = $dt->add(days => 1)->ymd;
|
# my $new_test = $dt->add(days => 1)->ymd;
|
||||||
# print $new_test . "\n";
|
# print $new_test . "\n";
|
||||||
|
|
||||||
$page_list2{$dt->add(days => 1)->ymd} = {
|
# $page_list2{$dt->add(days => 1)->ymd} = {
|
||||||
|
# title => $books[$book_list]{'title'},
|
||||||
|
# author => $books[$book_list]{'author'},
|
||||||
|
# page => $page_rand
|
||||||
|
# };
|
||||||
|
|
||||||
|
$page_list2{$dt->ymd} = {
|
||||||
title => $books[$book_list]{'title'},
|
title => $books[$book_list]{'title'},
|
||||||
author => $books[$book_list]{'author'},
|
author => $books[$book_list]{'author'},
|
||||||
page => $page_rand
|
page => $page_rand
|
||||||
};
|
};
|
||||||
|
$dt->add(days => 1);
|
||||||
|
|
||||||
# print $dt->add(days => 1)->ymd;
|
# print $dt->add(days => 1)->ymd;
|
||||||
# my $new_date = $dt->add(days => $l);
|
# my $new_date = $dt->add(days => $l);
|
||||||
@ -207,10 +224,10 @@ for ( my $l; $l < 365; $l++){
|
|||||||
# my $json_text = encode_json(\%books);
|
# my $json_text = encode_json(\%books);
|
||||||
my $json_text2 = $json->pretty->encode( \%page_list2 );
|
my $json_text2 = $json->pretty->encode( \%page_list2 );
|
||||||
|
|
||||||
my $js_text2 = "let book = " . $json_text2;
|
my $js_text2 = "let book_pages = " . $json_text2;
|
||||||
|
|
||||||
# write the file
|
# write the file
|
||||||
open(FH, '>', "test5.js") or die $!;
|
open(FH, '>', $book_pages_js) or die $!;
|
||||||
print FH $js_text2;
|
print FH $js_text2;
|
||||||
close(FH);
|
close(FH);
|
||||||
|
|
||||||
|
14
index.html
14
index.html
@ -36,7 +36,7 @@ this file uses:
|
|||||||
<script src="jquery-3.7.1.min.js"></script>
|
<script src="jquery-3.7.1.min.js"></script>
|
||||||
<script src="html2canvas.min.js"></script>
|
<script src="html2canvas.min.js"></script>
|
||||||
<script src="FileSaver.min.js"></script>
|
<script src="FileSaver.min.js"></script>
|
||||||
<script src="test5.js"></script>
|
<script src="book_pages.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
@ -69,11 +69,11 @@ $(document).ready(function(){
|
|||||||
// console.log(book[todayString]);
|
// console.log(book[todayString]);
|
||||||
|
|
||||||
// Make the header with the book info
|
// Make the header with the book info
|
||||||
$("#poem_header").html("<h2>" + book[todayString].title + "</h2>\n\n<h3>" + book[todayString].author + "</h3>\n");
|
$("#poem_header").html("<h2>" + book_pages[todayString].title + "</h2>\n\n<h3>" + book_pages[todayString].author + "</h3>\n");
|
||||||
|
|
||||||
// Add in the page, change the underscores to italics
|
// Add in the page, change the underscores to italics
|
||||||
// $("#spina").html(book.pages[14][6].replace(/(_([a-z0-9]+)_)/ig, "<i>$2</i>"));
|
// $("#spina").html(book.pages[14][6].replace(/(_([a-z0-9]+)_)/ig, "<i>$2</i>"));
|
||||||
$("#spina").html(book[todayString].page.replace(/(_([a-z0-9]+)_)/ig, "<i>$2</i>"));
|
$("#spina").html(book_pages[todayString].page.replace(/(_([a-z0-9]+)_)/ig, "<i>$2</i>"));
|
||||||
|
|
||||||
// format the text with span tags
|
// format the text with span tags
|
||||||
$("#spina p").each(function( index ) {
|
$("#spina p").each(function( index ) {
|
||||||
@ -123,7 +123,7 @@ $(document).ready(function(){
|
|||||||
todayFormatted = today.toString();
|
todayFormatted = today.toString();
|
||||||
|
|
||||||
// add the byline
|
// add the byline
|
||||||
$("#byline").html("<p>blackout poem inspired by " + book[todayString].title + " by " + book[todayString].author + "</p><p>composed on: " + todayFormatted) + "</p>";
|
$("#byline").html("<p>blackout poem inspired by " + book_pages[todayString].title + " by " + book_pages[todayString].author + "</p><p>composed on: " + todayFormatted) + "</p>";
|
||||||
|
|
||||||
// toggle the text on the button
|
// toggle the text on the button
|
||||||
$(this).text(function(i, text) {
|
$(this).text(function(i, text) {
|
||||||
@ -158,7 +158,7 @@ $(document).ready(function(){
|
|||||||
todayFormatted = today.toString();
|
todayFormatted = today.toString();
|
||||||
|
|
||||||
// add the meta to the copyed text
|
// add the meta to the copyed text
|
||||||
var poem_meta = "#dailyBlackoutPoetryChallenge\n\n" + $("#poem_list").text() + "\n\n" + book[todayString].title + " - " + todayFormatted;
|
var poem_meta = "#dailyBlackoutPoetryChallenge\n\n" + $("#poem_list").text() + "\n\n" + book_pages[todayString].title + " - " + todayFormatted;
|
||||||
navigator.clipboard.writeText(poem_meta);
|
navigator.clipboard.writeText(poem_meta);
|
||||||
}); // copy text w/meta
|
}); // copy text w/meta
|
||||||
|
|
||||||
@ -187,7 +187,9 @@ $(document).ready(function(){
|
|||||||
<header>
|
<header>
|
||||||
<h1>Daily <span class="purple">Blackout</span> Poetry Challenge</h1>
|
<h1>Daily <span class="purple">Blackout</span> Poetry Challenge</h1>
|
||||||
|
|
||||||
<p>Your daily blackout poetry challenge! Make a poem, save the poem, share the poem!</p><p>Tag the poem: #dailyBlackoutPoetryChallenge</p>
|
<p>Your daily blackout poetry challenge! Make a poem, save the poem, share the poem!</p>
|
||||||
|
|
||||||
|
<p>Tag the poem: #dailyBlackoutPoetryChallenge</p>
|
||||||
|
|
||||||
<p>Click on a word to select it, click on it again to unselect. When you’ve found your poem hit Blackout! Get a screen shot and copy the words below!</p>
|
<p>Click on a word to select it, click on it again to unselect. When you’ve found your poem hit Blackout! Get a screen shot and copy the words below!</p>
|
||||||
</header>
|
</header>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user