conditionally display OsmAnd download button; template proper apk url, size into same
This commit is contained in:
parent
cc69d322ca
commit
161d8d0e5f
3 changed files with 33 additions and 2 deletions
|
|
@ -223,11 +223,16 @@ h1.homepage-title {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply/Remove this class to conditionally
|
// Apply/Remove this class to conditionally
|
||||||
// display the card
|
// display the card using main.js
|
||||||
.hidden-card {
|
.hidden-card {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generic hidden class
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.card-icon {
|
.card-icon {
|
||||||
width: 60px;
|
width: 60px;
|
||||||
height: 60px;
|
height: 60px;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
// Checks to see what map files exist at /usb-butter/osm-map-files/ and displays them
|
// Checks to see what map files exist at /usb-butter/osm-map-files/ and displays them
|
||||||
// using the template hidden in the page
|
// using the template hidden in the page
|
||||||
|
|
||||||
|
OSM_PACKAGE = "net.osmand";
|
||||||
|
|
||||||
const getMaps = async (folder_href) => {
|
const getMaps = async (folder_href) => {
|
||||||
async function populateSpan(response) {
|
async function populateSpan(response) {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
@ -44,4 +46,28 @@ function renderMaps(files) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If OSM is in the F-Droid repo, show the download button
|
||||||
|
// and point to proper apk with proper size.
|
||||||
|
const getOsm = async () => {
|
||||||
|
repoRoot = '/usb-butter/appstore/fdroid/repo/';
|
||||||
|
json_url = repoRoot + 'index-v1.json';
|
||||||
|
const response = fetch(json_url).then(async (response) => {
|
||||||
|
const ix = await response.json();
|
||||||
|
if (ix.packages && ix.packages[OSM_PACKAGE] && ix.packages[OSM_PACKAGE].length > 0) {
|
||||||
|
const button = document.getElementById('osm-dl-button');
|
||||||
|
const links = button.querySelectorAll('a');
|
||||||
|
const apkName = ix.packages[OSM_PACKAGE][0]['apkName'];
|
||||||
|
const size = ix.packages[OSM_PACKAGE][0]['size'];
|
||||||
|
const sizeInMB = Math.floor(size / 1024 / 1024);
|
||||||
|
for (let link of links) {
|
||||||
|
link.href = repoRoot + apkName;
|
||||||
|
}
|
||||||
|
const cta = button.querySelector('.button-sub-text');
|
||||||
|
cta.textContent = `${sizeInMB} MB`;
|
||||||
|
button.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getOsm()
|
||||||
getMaps('/usb-butter/osm-map-files/');
|
getMaps('/usb-butter/osm-map-files/');
|
||||||
|
|
@ -15,7 +15,7 @@ custom_scripts: ["maps.js", "butter-dir-listing.js"]
|
||||||
|
|
||||||
<div class="step-label">{% t maps.sections.section1.step %}</div>
|
<div class="step-label">{% t maps.sections.section1.step %}</div>
|
||||||
<h2>{% t maps.sections.section1.title %}</h2>
|
<h2>{% t maps.sections.section1.title %}</h2>
|
||||||
<div class="btn-container">
|
<div id="osm-dl-button" class="btn-container hidden">
|
||||||
{% assign apk_url = site.baseurl | append: "/fdroid/repo/net.osmand.plus_471703.apk" %}
|
{% assign apk_url = site.baseurl | append: "/fdroid/repo/net.osmand.plus_471703.apk" %}
|
||||||
{% include fancybutton.html main_cta="maps.main_cta" sub_cta="maps.sub_cta" href=apk_url %}
|
{% include fancybutton.html main_cta="maps.main_cta" sub_cta="maps.sub_cta" href=apk_url %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue