WebSite

Package: Libraries.Web · Inherits from: Libraries.Network.NetworkExchangeListener, Libraries.Language.Object

WebSite holds everything on a website by where it lives: pages, and other responders that answer requests with data. It can write the pages to its folder, serve everything by location, or both. Either way, it first makes one stylesheet with exactly the rules the pages use, gives each styled element its one class name, and links the stylesheet into every page. Every location is inside the site and never starts with a slash, so "style/site.css" can only mean one place. Files a page uses, such as a table's data, live in the site's relative folder ("media" by default), and a page names them relative to it.

Example Code

use Libraries.Web.Page.all
use Libraries.Web.WebSite
use Libraries.Web.Styles.StyleOptions

class Main
    action Main
        StyleOptions options
        WebSite site
        site:SetFolder("html")

        WebPage home
        home:SetLocation("index.html")
        home:SetStyleOptions(options)
        site:AddPage(home)
        home:Title("Welcome")
        home:Section("About")
        home:Paragraph("Hello")

        site:Write()
        site:Serve(8080)
    end
end

Actions

AddLookSample(Libraries.Web.Page.WebPage page)

Adds an example of a page the site's server builds when someone asks for it, such as a page listing a reader's projects. The example is set up and styled with the site's pages, so its looks are in the stylesheet, but it is never written or served itself. Give it the same kind of content the real pages have, then prepare each real page with PrepareServedPage.

Parameters

Example

use Libraries.Web.WebSite
use Libraries.Web.Page.WebPage

WebSite site
WebPage example
site:AddLookSample(example)

AddPage(Libraries.Web.Page.WebPage page)

Adds a page to the site, at its location, and tells the page which site it is on. Add a page before setting it up, so it can find the site's files while it is built. A page can be written to a file and served.

Parameters

AddPlainPage(Libraries.Web.Page.WebPage page, text location)

Adds a page the site writes and serves exactly as the page makes itself, at the location given, for a page that doesn't know its own.

Parameters

AddPlainPage(Libraries.Web.Page.WebPage page)

Adds a page the site writes and serves exactly as the page makes itself: the site sets it up, but adds nothing to it (no stylesheet, no search and sharing tags, no checks). For pages made before the site's styling existed, which have their own look.

Parameters

Example

use Libraries.Web.WebSite
use Libraries.Web.Page.WebPage

WebSite site
WebPage page
page:SetLocation("old.html")
site:AddPlainPage(page)

AddResponder(Libraries.Web.ServerResponder responder)

Adds a responder that isn't a page, such as one that signs people in, at its location. It is served, but never written to a file.

Parameters

AddSeries(Libraries.Web.Series.PageSeries series)

Adds a series of pages, such as a course, to the site. A page can be in any number of series.

Parameters

AddSitemapFolder(text location)

Adds a folder the site doesn't build itself, such as documentation written by another program, to the sitemap: every page in it, and in the folders inside it.

Parameters

  • location text: The folder, inside the site's folder, such as "Libraries".

FinishContent()

Called once every page is set up, before the stylesheet is built and anything is written or served. It does nothing here. A subclass fills it in for anything that needs every page at once, such as adding pages built from what the others recorded; pages it adds then are styled and written like any other.

Example

use Libraries.Web.WebSite

class MySite is WebSite
    action FinishContent
        // build an index of every page here
    end
end

FinishServedPage(Libraries.Web.Page.WebPage page)

Called for each page the server builds, by PrepareServedPage, before the page is styled. It does nothing here. A subclass fills it in to finish a served page as FinishContent finishes the site's own, such as putting it in the site's frame; looks it adds must be ones the site's pages already have.

Parameters

GetAddress()

Returns the site's public address, or nothing if none was set.

Returns

text: The address.

GetFolder()

Returns the folder the site is written into.

Returns

text: The site's folder.

GetHomeSeries(Libraries.Web.Page.WebPage page)

Returns the series a page belongs to most, which its navigation follows when a reader arrives without following a series: the one the page set with SetHomeSeries, or its only series. A page in several series must set one, or the build stops.

Parameters

Returns

Libraries.Web.Series.PageSeries: Its home series, or undefined if it is in none.

GetLibraryCodeAddress(text className)

Returns the address of the page documenting a class, from the top of the site, for a link to it.

Parameters

  • className text: The class's full name, such as "Libraries.System.File".

Returns

text: The page's address, such as "/Libraries/System/File.html".

Example

use Libraries.Web.WebSite

WebSite site
output site:GetLibraryCodeAddress("Libraries.System.File")

GetPage(text location)

Returns the page at a location, or undefined if there is none.

Parameters

  • location text: Where the page lives, such as "index.html".

Returns

Libraries.Web.Page.WebPage: The page, or undefined.

GetPageIterator()

Returns every page on the site, in no particular order, for a subclass's FinishContent.

Returns

Libraries.Containers.Iterator<Libraries.Web.Page.WebPage>: The pages.

GetPublicAddress(text location)

Returns the full public address of a location on the site, such as "https://quorumlanguage.com/tutorials/start.html".

Parameters

  • location text: A location on the site, with no leading slash.

Returns

text: The full public address.

GetRelativeFile(text location)

Returns a file in the site's relative folder. A page uses this to find a file it names, such as a table's data.

Parameters

  • location text: The file's location inside the relative folder, such as "scenes/Vocabulary.csv".

Returns

Libraries.System.File: The file.

Example

use Libraries.Web.WebSite
use Libraries.System.File

WebSite site
site:SetFolder("html")
File file = site:GetRelativeFile("scenes/Vocabulary.csv")

GetRelativeFolder()

Returns the folder, inside the site, that pages name their files relative to.

Returns

text: The relative folder, such as "media".

GetResponder(text location)

Returns whatever answers requests at a location, page or not, or undefined if there is nothing there.

Parameters

  • location text: A location, such as "index.html".

Returns

Libraries.Web.ServerResponder: The responder, or undefined.

GetSeriesList()

Returns every series on the site, in the order added.

Returns

Libraries.Containers.Array<Libraries.Web.Series.PageSeries>: The series.

GetSeriesOf(Libraries.Web.Page.WebPage page)

Returns every series a page is in, in the order the series were added to the site.

Parameters

Returns

Libraries.Containers.Array<Libraries.Web.Series.PageSeries>: The series it is in, or none.

GetSiteName()

Returns the site's name, as link previews show it.

Returns

text: The site's name.

GetStyleOptions()

Returns the look for pages the site builds itself.

Returns

Libraries.Web.Styles.StyleOptions: The look.

HasAccessibilityChecks()

Sets whether every page is checked for accessibility problems once it is finished, frame and all, before the site is written or served (see WebAccessibilityChecker). If any page has problems, the build stops and lists them all. The default is off.

Returns

boolean

Example

use Libraries.Web.WebSite

WebSite site
site:SetAccessibilityChecks(true)

IsPlainPage(Libraries.Web.Page.WebPage page)

Returns true if a page was added with AddPlainPage, so the site adds nothing to it.

Parameters

Returns

boolean: Whether the page is written as it makes itself.

PrepareServedPage(Libraries.Web.Page.WebPage page)

Gets a page the site's server built when asked ready to send, as the site's own pages are: finished as the site finishes its pages (FinishServedPage, such as a site's frame), each element given its class name from the stylesheet, and the stylesheet linked. Call page:SetWebSite first, then the page's Setup, then this, once the site is written or serving. An element whose look the stylesheet doesn't have gets no class name and shows unstyled; add an example of the page with AddLookSample so the stylesheet has its looks.

Parameters

Returns

integer: How many of the page's looks the stylesheet doesn't have: 0 when every element is styled.

ResponseReceived(Libraries.Network.NetworkExchange exchange)

Answers one request by its location. WebServer calls this; people making pages don't.

Parameters

Serve(integer port)

Starts answering requests on a port: each request goes to whatever is at its location, and the stylesheet (unless every page is plain) is served at its own location. This keeps running until the server is stopped.

Parameters

  • port integer: The port to listen on, such as 8080.

SetAccessibilityChecks(boolean value)

Sets whether every page is checked for accessibility problems once it is finished, frame and all, before the site is written or served (see WebAccessibilityChecker). If any page has problems, the build stops and lists them all. The default is off.

Parameters

  • value boolean: True to check every page.

Example

use Libraries.Web.WebSite

WebSite site
site:SetAccessibilityChecks(true)

SetAddress(text value)

Sets the site's public address, such as "https://quorumlanguage.com", with no slash at the end. Every page's canonical address (the one address search engines should use for it), its sharing address, and the sitemap are made from this. Pages always name the public site, even when the site is run locally.

Parameters

  • value text: The site's public address.

Example

use Libraries.Web.WebSite

WebSite site
site:SetAddress("https://quorumlanguage.com")

SetDefaultShareImage(text location, text imageDescription)

Sets the picture shown when a page without its own is shared, from the site's relative folder, with a description of what it shows.

Parameters

  • location text: The picture, inside the site's relative folder.
  • imageDescription text: What the picture shows.

SetFolder(text folder)

Sets the folder the site is written into, such as "html". Set it before pages are set up, since they find their files inside it.

Parameters

  • folder text: The site's folder.

Example

use Libraries.Web.WebSite

WebSite site
site:SetFolder("html")

SetHomeLocation(text location)

Sets which page answers a request for the site itself, with no location ("/"). The default is "index.html".

Parameters

  • location text: The home page's location.

SetLibraryCodeFolder(text location)

Sets the folder, inside the site, where the pages documenting a code library live. A class such as Libraries.System.File has its page at this folder plus "Libraries/System/File.html". The default is the top of the site.

Parameters

  • location text: The folder, inside the site, with no leading slash.

Example

use Libraries.Web.WebSite

WebSite site
site:SetLibraryCodeFolder("documentation")

SetRelativeFolder(text location)

Sets the folder, inside the site, that pages name their files relative to. The default is "media", so a page's "scenes/Vocabulary.csv" is the site's "media/scenes/Vocabulary.csv".

Parameters

  • location text: The folder, inside the site, with no leading slash.

Example

use Libraries.Web.WebSite

WebSite site
site:SetRelativeFolder("media")

SetRobotsLocation(text location)

Sets where the robots file is written, relative to the site's folder. The default is "robots.txt", at the top of the site, the only place search engines read it.

Parameters

  • location text: Where the robots file goes.

SetSiteName(text value)

Sets the site's name, as link previews show it, such as "Quorum Programming Language".

Parameters

  • value text: The site's name.

SetSitemapLocation(text location)

Sets where the sitemap is written, relative to the site's folder. The default is "sitemap.xml", at the top of the site, where search engines look for it.

Parameters

  • location text: Where the sitemap goes.

SetStyleOptions(Libraries.Web.Styles.StyleOptions options)

Gives the site the look for pages it builds itself, such as a report or an index that a subclass adds. Pages added by people are handed their own.

Parameters

SetStyleSheetLocation(text location)

Sets where the site's stylesheet lives, relative to the site's folder. The default is "style/site.css".

Parameters

  • location text: Where the stylesheet goes.

SetTitleEnding(text value)

Sets the words added to the end of every page's browser tab title, such as " - Quorum Programming Language", so pages don't type them. A page that calls SetWebPageTitle itself keeps its own.

Parameters

  • value text: The ending, including any space or dash before it.

Write()

Writes the site into its folder: the stylesheet (unless every page is plain), every page, and, if the site has an address, the sitemap and robots file. Responders that aren't pages aren't written.

Inherited Actions

3 actions from Libraries.Language.Object