Skip to content

Instantly share code, notes, and snippets.

@panesofglass
Last active June 4, 2020 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panesofglass/b39d32bb7a8866e2b11e4305d6e1ea1b to your computer and use it in GitHub Desktop.
Save panesofglass/b39d32bb7a8866e2b11e4305d6e1ea1b to your computer and use it in GitHub Desktop.
Simple Static Page Generator
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- master
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v1
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v0.0.1-preview
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_GENTLE_CLIFF_06D430810 }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match you app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/" # App source code path
api_location: "api" # Api source code path - optional
app_artifact_location: "" # Built app content directory - optional
###### End of Repository/Build Configurations ######
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v0.0.1-preview
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_GENTLE_CLIFF_06D430810 }}
action: "close"
#r "nuget:AngleSharp"
#r "nuget:Deedle"
open System
open System.IO
open AngleSharp
open AngleSharp.Html.Parser
open Deedle
let src = DirectoryInfo(__SOURCE_DIRECTORY__)
let root = src.Parent.FullName
let dataDir = Path.Combine(root, "data")
let srcDir = src.FullName
let outDir = Path.Combine(root, "out")
// Load and parse CSV
let csvPath = Path.Combine(dataDir, "services.csv")
let df = Frame.ReadCsv(csvPath)
//df.Print()
let now = DateTime.Today
let lastSunday = now.AddDays(-(float now.DayOfWeek))
let nextSunday = lastSunday.AddDays(7.)
let services =
df.Rows |> Series.filterValues (fun row ->
let date = row.GetAs<DateTime>("Date")
lastSunday < date && date <= nextSunday)
//services.Print()
let svcs =
services |> Series.mapValues (fun row ->
let date = row.GetAs<DateTime>("Date")
let time = row.GetAs<string>("Time").Split(':')
let dt = date.AddHours(float time.[0]).AddMinutes(float time.[1])
let title = row.GetAs<string>("Title")
let lang = row.GetAs<string>("Language")
sprintf "%s %s (%s)" (dt.ToString("d")) title lang)
//svcs.Print()
// Load and parse HTML
let htmlPath = Path.Combine(srcDir, "index.html")
let context = BrowsingContext.New(Configuration.Default)
let parser = context.GetService<IHtmlParser>()
let doc = using (File.OpenRead htmlPath) parser.ParseDocument
// Set the correct form action
let form : Html.Dom.IHtmlFormElement = downcast doc.GetElementsByTagName("form").[0]
form.Action <- "https://some-function-api.azurewebsites.net/"
// Add the options for the upcoming week.
let frag = doc.CreateDocumentFragment()
for key in svcs.Keys do
let opt : Html.Dom.IHtmlOptionElement = downcast doc.CreateElement("option")
opt.Value <- svcs.[key]
opt.TextContent <- svcs.[key]
frag.AppendChild(opt) |> ignore
let select = doc.GetElementsByTagName("select").[0]
select.AppendChild(frag) |> ignore
// Clean the out directory
if (Directory.Exists outDir) then Directory.Delete(outDir, recursive=true)
Directory.CreateDirectory outDir
// Write the result to the outDir
let outPath = Path.Combine(outDir, "index.html")
// Prettified
using (File.CreateText outPath) (fun writer -> writer.Write(doc.Prettify()))
// Minified
using (File.CreateText outPath) (fun writer -> writer.Write(doc.Minify()))
// Copy style and script
File.Copy(Path.Combine(srcDir, "style.css"), Path.Combine(outDir, "style.css"))
// Write the timestamp
let lastWriteTime = DateTimeOffset(File.GetLastWriteTime(outPath))
using (File.CreateText(Path.Combine(outDir, "timestamp"))) (fun writer -> writer.Write(lastWriteTime.ToUnixTimeMilliseconds()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment