Skip to content

Commit

Permalink
Improve word count algorithm, home page format
Browse files Browse the repository at this point in the history
  • Loading branch information
brightly-salty committed Aug 29, 2022
1 parent f9896cd commit 975f544
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 55 deletions.
76 changes: 38 additions & 38 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,90 +33,90 @@ <h2>Welcome to my digital library!</h2>

<strong>Theology and non-resistance</strong>

<p><a href="./books/everlasting-man"><em>The Everlasting Man</em> by G. K. Chesterton in 1927 (100k words)</a></p>
<p>1927: <a href="./books/everlasting-man"><em>The Everlasting Man</em> by G. K. Chesterton (100k words)</a></p>

<p><a href="./books/garrison-nonresistance"><em>William Lloyd Garrison on Non-Resistance</em> by Fanny Garrison Villard in 1924 (16k words)</a></p>
<p>1924: <a href="./books/garrison-nonresistance"><em>William Lloyd Garrison on Non-Resistance</em> by Fanny Garrison Villard (16k words)</a></p>

<p><a href="./books/atonement-nonresistance"><em>Atonement and Non-Resistance</em> by William Wilson in 1923 (13k words)</a></p>
<p>1923: <a href="./books/atonement-nonresistance"><em>Atonement and Non-Resistance</em> by William Wilson (13k words)</a></p>

<p><a href="./books/orthodoxy"><em>Orthodoxy</em> by G. K. Chesterton in 1908 (60k words)</a></p>
<p>1908: <a href="./books/orthodoxy"><em>Orthodoxy</em> by G. K. Chesterton (63k words)</a></p>

<p><a href="./books/patriotism-peace"><em>Patriotism or Peace: Letter to Manson</em> by Leo Tolstoy in 1896 (3200 words)</a></p>
<p>1896: <a href="./books/patriotism-peace"><em>Patriotism or Peace: Letter to Manson</em> by Leo Tolstoy (3.2k words)</a></p>

<p><a href="./books/on-nonresistance"><em>On Non-Resistance: Letter to Ernest Howard Crosby</em> by Leo Tolstoy in 1896 (4k words)</a></p>
<p>1896: <a href="./books/on-nonresistance"><em>On Non-Resistance: Letter to Ernest Howard Crosby</em> by Leo Tolstoy (4.1k words)</a></p>

<p><a href="./books/kingdom-within"><em>The Kingdom of God is Within You</em> by Leo Tolstoy in 1894 (120k words)</a></p>
<p>1894: <a href="./books/kingdom-within"><em>The Kingdom of God is Within You</em> by Leo Tolstoy (120k words)</a></p>

<p><a href="./books/christianity-patriotism"><em>Christianity and Patriotism</em> by Leo Tolstoy in 1894 (21k words)</a></p>
<p>1894: <a href="./books/christianity-patriotism"><em>Christianity and Patriotism</em> by Leo Tolstoy (21k words)</a></p>

<p><a href="./books/civil-disobedience"><em>Civil Disobedience</em> by Henry David Thoreau in 1888 (9k words)</a></p>
<p>1888: <a href="./books/civil-disobedience"><em>Civil Disobedience</em> by Henry David Thoreau (9.4k words)</a></p>

<p><a href="./books/what-christian-may"><em>What a Christian May Do, and What Not</em> by Leo Tolstoy in 1887 (1000 words)</a></p>
<p>1887: <a href="./books/what-christian-may"><em>What a Christian May Do, and What Not</em> by Leo Tolstoy (1.0k words)</a></p>

<p><a href="./books/remarks-ballou"><em>Non-Resistance in relation to Human Governments</em> by Adin Ballou in 1839 (6k words)</a></p>
<p>1839: <a href="./books/remarks-ballou"><em>Non-Resistance in relation to Human Governments</em> by Adin Ballou (6.8k words)</a></p>


<strong>Political economy and political science</strong>

<p><a href="./books/flight-from-city"><em>Flight from the City</em> by Ralph Borsodi in 1933 (40k words)</a></p>
<p>1933: <a href="./books/flight-from-city"><em>Flight from the City</em> by Ralph Borsodi (42k words)</a></p>

<p><a href="./books/outline-sanity"><em>Outline of Sanity</em> by G. K. Chesterton in 1926 (60k words)</a></p>
<p>1926: <a href="./books/outline-sanity"><em>Outline of Sanity</em> by G. K. Chesterton (62k words)</a></p>

<p><a href="./books/economics-helen"><em>Economics for Helen</em> by Hilaire Belloc in 1924 (50k words)</a></p>
<p>1924: <a href="./books/economics-helen"><em>Economics for Helen</em> by Hilaire Belloc (54k words)</a></p>

<p><a href="./books/christian-sociology"><em>Towards a Christian Sociology</em> by Arthur J. Penty in 1923 (50k words)</a></p>
<p>1923: <a href="./books/christian-sociology"><em>Towards a Christian Sociology</em> by Arthur J. Penty (59k words)</a></p>

<p><a href="./books/control-distribution"><em>The Control and Distribution of Production</em> by C. H. Douglas in 1922 (30k words)</a></p>
<p>1922: <a href="./books/control-distribution"><em>The Control and Distribution of Production</em> by C. H. Douglas (30k words)</a></p>

<p><a href="./books/eugenics-evils"><em>Eugenics and Other Evils</em> by G. K. Chesterton in 1922 (40k words)</a></p>
<p>1922: <a href="./books/eugenics-evils"><em>Eugenics and Other Evils</em> by G. K. Chesterton (47k words)</a></p>

<p><a href="./books/saw-america"><em>What I Saw in America</em> by G. K. Chesterton in 1922 (90k words)</a></p>
<p>1922: <a href="./books/saw-america"><em>What I Saw in America</em> by G. K. Chesterton (90k words)</a></p>

<p><a href="./books/acquisitive-society"><em>The Acquisitive Society</em> by R. H. Tawney in 1921 (60k words)</a></p>
<p>1921: <a href="./books/acquisitive-society"><em>The Acquisitive Society</em> by R. H. Tawney (63k words)</a></p>

<p><a href="./books/guilds-trade"><em>Guilds, Trade, and Agriculture</em> by Arthur Penty in 1921 (30k words)</a></p>
<p>1921: <a href="./books/guilds-trade"><em>Guilds, Trade, and Agriculture</em> by Arthur Penty (30k words)</a></p>

<p><a href="./books/economic-democracy"><em>Economic Democracy</em> by C. H. Douglas in 1920 (23k words)</a></p>
<p>1920: <a href="./books/economic-democracy"><em>Economic Democracy</em> by C. H. Douglas (23k words)</a></p>

<p><a href="./books/superstition-divorce"><em>The Superstition of Divorce</em> by G. K. Chesterton in 1920 (24k words)</a></p>
<p>1920: <a href="./books/superstition-divorce"><em>The Superstition of Divorce</em> by G. K. Chesterton (24k words)</a></p>

<p><a href="./books/mutual-banking"><em>Mutual Banking</em> by William B. Greene in 1919 (28k words)</a></p>
<p>1919: <a href="./books/mutual-banking"><em>Mutual Banking</em> by William B. Greene (28k words)</a></p>

<p><a href="./books/guilds-crisis"><em>Guilds and the Social Crisis</em> by Arthur Penty in 1919 (21k words)</a></p>
<p>1919: <a href="./books/guilds-crisis"><em>Guilds and the Social Crisis</em> by Arthur Penty (21k words)</a></p>

<p><a href="./books/the-free-press"><em>The Free Press</em> by Hilaire Belloc in 1918 (18k words)</a></p>
<p>1918: <a href="./books/the-free-press"><em>The Free Press</em> by Hilaire Belloc (18k words)</a></p>

<p><a href="./books/utopia-usurers"><em>Utopia of Usurers</em> by G. K. Chesterton in 1917 (10k words)</a></p>
<p>1917: <a href="./books/utopia-usurers"><em>Utopia of Usurers</em> by G. K. Chesterton (10k words)</a></p>

<p><a href="./books/servile-state"><em>The Servile State</em> by Hilaire Belloc in 1912 (36k words)</a></p>
<p>1912: <a href="./books/servile-state"><em>The Servile State</em> by Hilaire Belloc (36k words)</a></p>

<p><a href="./books/whats-wrong"><em>What's Wrong with the World</em> by G. K. Chesterton in 1910 (50k words)</a></p>
<p>1910: <a href="./books/whats-wrong"><em>What's Wrong with the World</em> by G. K. Chesterton (59k words)</a></p>

<p><a href="./books/restoration-guild"><em>The Restoration of the Guild System</em> by Arthur Penty in 1906 (18k words)</a></p>
<p>1906: <a href="./books/restoration-guild"><em>The Restoration of the Guild System</em> by Arthur Penty (18k words)</a></p>

<p><a href="./books/condition-labor"><em>The Condition of Labor</em> by Henry George in 1891 (40k words)</a></p>
<p>1891: <a href="./books/condition-labor"><em>The Condition of Labor</em> by Henry George (46k words)</a></p>

<p><a href="./books/social-problems"><em>Social Problems</em> by Henry George in 1883 (70k words)</a></p>
<p>1883: <a href="./books/social-problems"><em>Social Problems</em> by Henry George (75k words)</a></p>

<p><a href="./books/agrarian-justice"><em>Agrarian Justice</em> by Thomas Paine in 1797 (6k words)</a></p>
<p>1797: <a href="./books/agrarian-justice"><em>Agrarian Justice</em> by Thomas Paine (6.1k words)</a></p>


<strong>History and biography</strong>

<p><a href="./books/st-francis"><em>St. Francis of Assisi</em> by G. K. Chesterton in 1923 (40k words)</a></p>
<p>1923: <a href="./books/st-francis"><em>St. Francis of Assisi</em> by G. K. Chesterton (43k words)</a></p>

<p><a href="./books/guildsman-history"><em>A Guildsman's Interpretation of History</em> by Arthur Penty in 1920 (100k words)</a></p>
<p>1920: <a href="./books/guildsman-history"><em>A Guildsman's Interpretation of History</em> by Arthur Penty (100k words)</a></p>

<p><a href="./books/tolstoy-philosophy"><em>Count Tolstoy and His Philosophy of Life</em> by Ernest Howard Crosby in 1900 (12k words)</a></p>
<p>1900: <a href="./books/tolstoy-philosophy"><em>Count Tolstoy and His Philosophy of Life</em> by Ernest Howard Crosby (12k words)</a></p>


<strong>Fiction and parable</strong>

<p><a href="./books/man-thursday"><em>The Man who was Thursday</em> by G. K. Chesterton in 1908 (50k words)</a></p>
<p>1908: <a href="./books/man-thursday"><em>The Man who was Thursday</em> by G. K. Chesterton (57k words)</a></p>

<p><a href="./books/napoleon-notting"><em>The Napoleon of Notting Hill</em> by G. K. Chesterton in 1904 (50k words)</a></p>
<p>1904: <a href="./books/napoleon-notting"><em>The Napoleon of Notting Hill</em> by G. K. Chesterton (54k words)</a></p>

<p><a href="./books/where-love"><em>Where love is there God is also</em> by Leo Tolstoy in 1887 (5k words)</a></p>
<p>1887: <a href="./books/where-love"><em>Where love is there God is also</em> by Leo Tolstoy (5.1k words)</a></p>



Expand Down
29 changes: 13 additions & 16 deletions site.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import System.FilePath (takeBaseName, takeDirectory, (</>))
import Text.HTML.TagSoup (Tag (..))
import Prelude hiding (words)
import Control.Arrow (second)
import GHC.Float

--------------------------------------------------------------------------------
main :: IO ()
Expand Down Expand Up @@ -144,22 +145,18 @@ instance FromJSON Book

prettyWords :: Book -> String
prettyWords book =
let ws = words book in
if ws > 400000
then show (ws `div` 100000) <> "00k"
else
if ws > 40000
then show (ws `div` 10000) <> "0k"
else
if ws > 4000
then show (ws `div` 1000) <> "k"
else
if ws > 400
then show (ws `div` 100) <> "00"
else
if ws > 40
then show (ws `div` 10) <> "0"
else show ws
let wds = fromIntegral $ words book in
let order = double2Int (logBase 10 wds) - 1 in
let [c1, c2] = show $ double2Int $ wds / (10 ** (fromIntegral order)) in
case order of
1 -> c1:c2:"0"
2 -> c1:'.':c2:"k"
3 -> c1:c2:"k"
4 -> c1:c2:"0k"
5 -> c1:'.':c2:"m"
6 -> c1:c2:"m"
7 -> c1:c2:"0m"
_ -> error $ show order

compareBooks :: Book -> Book -> Ordering
compareBooks a b = compare (year b) (year a)
Expand Down
2 changes: 1 addition & 1 deletion templates/hakyll.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1>$title$</h1>
$for(categories)$
<strong>$category$</strong>
$for(books)$
<p><a href="/books/$tag$"><em>$title$</em> by $author$ in $year$ ($words$ words)</a></p>
<p>$year$: <a href="/books/$tag$"><em>$title$</em> by $author$ ($words$ words)</a></p>
$endfor$
$endfor$
$endif$
Expand Down

0 comments on commit 975f544

Please sign in to comment.