Tuesday, May 8, 2018

Why I haven't updated the GA App and its book links in a few years

What happened is that I was putting the books on my onedrive and then creating a link url on the site. The urls had a fixed format, with an id parameter. I store the id with the book record in the books table, and when generating the page HTML, generate the book's onedrive url with the id. A couple years ago, onedrive changed the format of their urls. The old book urls still work, but new urls have a different format. So I need to rewrite the code that generates the url. But I can't. I wrote the GA app four years ago, and Microsoft's changed its web tools (moved from old .NET to new .Net Core -- open source, works on Mac and Linux) and Visual Studio no longer supports the old .NET tools I used four years ago. So I need to upgrade to .NET core to compile any new code and rebuild the website. And I haven't got around to that upgrade project yet. Currently I'm more interested in learning client technologies, pushing more work to the browser, just serving files, and not having to keep a database running in the cloud to support the app.

Sunday, February 18, 2018

How to generate the Volpi book into a single file

Each page in the Volpi translation app is in a separate HTML file. I edit and update the individual files, and I don't maintain a single file with all of the book's pages.

However, you can generate a single HTML file with all the pages yourself, by pulling the individual pages from the app and concatenating them into a single file.

Here's how.

First create a start.html file with the HTML tags at the top:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Franco Volpi - Heidegger and Aristotle</title>
</head>
<body>
<h1>Franco Volpi - Heidegger and Aristotle</h1>
<h2>Translated by Pete Ferreira</h2>
<hr/><br/><br/>


Then create a end.html file with the HTML tags at the bottom:

</body>
</html>


Then use this PowerShell script to concatenate start.html, all the pages from the app, and end.html.

$bookContent = Get-Content 'start.html' For ($pagenumber=1; $pagenumber -lt 118; $pagenumber++) { $paddedpagenumber = ("{0:D3}" -f $pagenumber) $url = "http://beyng.com/volpi/assets/EN/Volpi.$paddedpagenumber.html" $resp = Invoke-WebRequest -URI $url $bookContent += "<br/><br/><p style=""text-align:center"">$pagenumber</p>`n`r"
$bookContent += [system.Text.Encoding]::UTF8.GetString($resp.RawContentStream.ToArray()) } $bookContent += Get-Content 'end.html' $bookContent | Out-File VolpiBook.html

In between each page, the script inserts HTML with the page number. The padded page number is required for the page URLs - e.g. page 1 as 001. The UTF8.GetString stuff is required to keep the Greek characters from getting munged.