-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor fixes + sitemap generation (#631)
- Loading branch information
Showing
15 changed files
with
273 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# <?xml version="1.0" encoding="utf-8" standalone="yes" ?> | ||
# <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
# <url> | ||
# <loc>http://www.example.com/</loc> | ||
# ?<lastmod>2005-01-01</lastmod> | ||
# ?<changefreq>monthly</changefreq> | ||
# ?<priority>0.8</priority> | ||
# </url> | ||
# </urlset> | ||
# | ||
# TODO | ||
# allow {{sitemap_exclude}} for a HTML page to avoid having it in sitemap | ||
# | ||
|
||
struct SMOpts | ||
lastmod::Date # 2005-01-01 -- format YYYY-MM-DD | ||
changefreq::String # one of... | ||
priority::Float64 # | ||
function SMOpts(l, c, p) | ||
c = lowercase(c) | ||
allowedf = ("always", "hourly", "daily", "weekly", "monthly", | ||
"yearly", "never") | ||
assertf = """ | ||
Given change frequency on $(FD_ENV[:SOURCE]) is invalid according to | ||
sitemap specifications, expected one of $allowedf. | ||
""" | ||
assertp = """ | ||
Given priority on $(FD_ENV[:SOURCE]) is invalid according to sitemap | ||
specifications, expected a floating point number between 0 and 1. | ||
""" | ||
@assert c in allowedf assertf | ||
@assert 0 <= p <= 1 assertp | ||
return new(l, c, p) | ||
end | ||
end | ||
|
||
const SITEMAP_DICT = LittleDict{String,SMOpts}() | ||
|
||
""" | ||
$SIGNATURES | ||
Add an entry to `SITEMAP_DICT`. | ||
""" | ||
function add_sitemap_item(; html=false) | ||
loc = url_curpage() | ||
locvar(:sitemap_exclude) && return nothing | ||
if !html | ||
lastmod = locvar(:fd_mtime) | ||
changefreq = locvar(:sitemap_changefreq) | ||
priority = locvar(:sitemap_priority) | ||
else | ||
# use default which can be overwritten in a {{sitemap_opts ...}} | ||
fp = joinpath(path(:folder), locvar(:fd_rpath)) | ||
lastmod = Date(unix2datetime(stat(fp).mtime)) | ||
changefreq = "monthly" | ||
priority = 0.5 | ||
end | ||
res = SITEMAP_DICT[loc] = SMOpts(lastmod, changefreq, priority) | ||
return res | ||
end | ||
|
||
""" | ||
$SIGNATURES | ||
Generate a `sitemap.xml`, if one already exists, it will be replaced. | ||
""" | ||
function sitemap_generator() | ||
dst = joinpath(path(:site), "sitemap.xml") | ||
isfile(dst) && rm(dst) | ||
io = IOBuffer() | ||
println(io, """ | ||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
""") | ||
base_url = globvar(:website_url) | ||
for (k, v) in SITEMAP_DICT | ||
key = joinpath(escapeuri.(split(k, '/'))...) | ||
loc = "<loc>$(joinpath(base_url, key))</loc>" | ||
lastmod = ifelse(v.lastmod > Date(1), | ||
"<lastmod>$(v.lastmod)</lastmod>", "") | ||
changefreq = "<changefreq>$(v.changefreq)</changefreq>" | ||
priority = "<priority>$(v.priority)</priority>" | ||
write(io, """ | ||
<url> | ||
$loc | ||
$lastmod | ||
$changefreq | ||
$priority | ||
</url> | ||
""") | ||
end | ||
println(io, "</urlset>") | ||
write(dst, take!(io)) | ||
return nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
1 comment
on commit 184b095
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/22043
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
git tag -a v0.10.2 -m "<description of version>" 184b09563eac60fa3f683236b835c93319427d2c
git push origin v0.10.2
@JuliaRegistrator register