diff --git a/_data/repositories.yml b/_data/repositories.yml index 5b1c10b686471c0eac37fb962e35a63020b59097..308720ab0317ab7d748383894201bd2b031097e4 100644 --- a/_data/repositories.yml +++ b/_data/repositories.yml @@ -1,2 +1,2 @@ sources: - - https://git.fairkom.net/tonyford/myp2p-orders + - https://git.fairkom.net/tonyford/myp2p diff --git a/_includes/overview.html b/_includes/overview.html index 03819279e03cbec5a8d3930cd0665cb22a9771e6..39aa47f1d29101c96acdf653eaacc4ed1d18db4a 100644 --- a/_includes/overview.html +++ b/_includes/overview.html @@ -9,7 +9,7 @@ {% for c in cat %} {% capture ID %}{{ site.data.categories[c].ID }}{% endcapture %} - <li onclick="$('.orderlist-div').toggleClass('d-none',true); $('.cat-{{ ID }}').toggleClass('d-none',false); $('.categories li').toggleClass('active', false ); $(this).toggleClass('active',true);">{{ site.data.categories[c].title | map: include.ln }} [{{ site.categories[ID] | size }}]</li> + <li onclick="get_by_cat(this,'{{ID}}')">{{ site.data.categories[c].title | map: include.ln }} [{{ site.categories[ID] | size }}]</li> {% endfor %} </ul> </div> @@ -21,17 +21,18 @@ <div class="orderlist-div cat-{{ ID }}"> <div class="orderlist-date"> - {{ o.date | slice: 0,10 }} <div class="image">{% if o.image-profile == 'img' %}<img src="{{ o.image }}">{% else if o.image-profile == 'imgbb'%}{{ o.image }}{% endif %}</div> </div> <div class="orderlist-title"> - <u>{{ o.headline | truncate: 32 }}</u><br> - <small><lang>#{{ o.ln }}</lang> <used>#{{ o.condition }}</used> <tags>#{{ o.tags }}</tags></small><br> + <a href="{{ o.git-repo }}/blob/master/{{ o.order-title }}" target="git-order"><u>{{ o.headline | truncate: 32 }}</u></a> <a href="{{ o.git-profile }}" target="git-profile"><span class="feather-icon icon-user"></span></a> <a href="{{ o.git-repo }}/issues/new?issue[title]={{ o.order-title }}" target="git-contact"><span class="feather-icon icon-mail"></span></a><br> + <small><lang><span class="feather-icon icon-tag"></span>{{ o.ln }}</lang> <used><span class="feather-icon icon-tag"></span>{{ o.condition }}</used> <tags><span class="feather-icon icon-tag"></span>{{ o.tags }}</tags> <span class="d-none distance-data">{{ o.latitude }},{{ o.longitude }}</span> <span class="distance"></span></small><br> <div><small>{{ o.description }}</small></div> </div> - <div class="orderlist-price">{% if o.min-size > 0 %}{{ o.min-size }}..{% endif %}{{ o.max-size }} {{ o.unit }}<br>( {{ o.price-per-unit | decimals }} {{ o.price-currency }} / {{ o.unit }} )<br>( {% capture price_ex %}{{ site.data.price-sources[o.price-source].price[o.price-currency] }}{% endcapture %}{% if price_ex != "" %}{{ price_ex }}{% else %}{{ o.price-source }}{% endif %} {{ o.price-currency }} / FAIR )<br><i>{% if price_ex != "" %}<a href="{{ site.data.price-sources[o.price-source].www }}">{{ o.price-source }}</a>{% else %}fixed price{% endif %}</i></div> + <div class="orderlist-price">{% if o.min-size > 0 %}{{ o.min-size }}..{% endif %}{{ o.max-size }} {{ o.unit }}<br>( {{ o.price-per-unit | decimals }} {{ o.price-currency }} / {{ o.unit }} )<br>( {% capture price_ex %}{{ site.data.price-sources[o.price-source].price[o.price-currency] }}{% endcapture %}{% capture price %}{% if price_ex != "" %}{{price_ex}}{% else %}{{ o.price-source }}{% endif %}{% endcapture %}{{ price }} {{ o.price-currency }} / FAIR )<br><i>{% if price_ex != "" %}<a href="{{ site.data.price-sources[o.price-source].www }}">{{ o.price-source }}</a>{% else %}fixed price{% endif %}</i> + <br><br><font class="faircoin-price">{{ o.price-per-unit | divided_by: price | decimals }} FAIR</font> + </div> </div> {% endfor %} {% endfor %} diff --git a/_layouts/default.html b/_layouts/default.html index 65370795c87b862163dc3a96836e3c3512f05a69..aba72762848726322482a1e59e5a869b15fe0c4b 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -11,6 +11,7 @@ <script src="https://cdn.rawgit.com/michalsnik/aos/2.1.1/dist/aos.js"></script> <script src="{{ site.baseurl }}/assets/js/simple-jekyll-search.js"></script> <script src="{{ site.baseurl }}/assets/js/jquery.min.js"></script> + <script src="{{ site.baseurl }}/assets/js/script.js"></script> <script> AOS.init({ once: true diff --git a/assets/js/script.js b/assets/js/script.js new file mode 100644 index 0000000000000000000000000000000000000000..404f4f560561d2ba565cf4d37eb0c29eb878d68c --- /dev/null +++ b/assets/js/script.js @@ -0,0 +1,49 @@ +$( document ).ready(function() { + get_distances(); +}); + +function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) { + var R = 6371; // Radius of the earth in km + var dLat = deg2rad(lat2-lat1); // deg2rad below + var dLon = deg2rad(lon2-lon1); + var a = + Math.sin(dLat/2) * Math.sin(dLat/2) + + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * + Math.sin(dLon/2) * Math.sin(dLon/2) + ; + var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); + var d = R * c; // Distance in km + return d; +} + +function deg2rad(deg) { + return deg * (Math.PI/180) +} + +function get_by_cat(obj, ID){ + $('.orderlist-div').toggleClass('d-none',true); + $('.cat-'+ID).toggleClass('d-none',false); + $('.categories li').toggleClass('active', false ); + $(obj).toggleClass('active',true); +} + +function get_distances(){ + var url_string = window.location.href; + var url = new URL(url_string); + var lat = url.searchParams.get('lat'); + var long = url.searchParams.get('long'); + if( lat == null || long == null ){ + lat=-100; + } + if( lat >= -90 && lat <= 90 && long >=-180 && long <= 180 ){ + } else { + return; + } + + $.each( $('.distance'), function(i,v){ + var geo=$( $(v).context.previousElementSibling ).text(); + var llat=geo.split(/,/g)[0]; + var llong=geo.split(/,/g)[1]; + $(v).html('<span class="feather-icon icon-map-pin"></span> ' + Math.round( getDistanceFromLatLonInKm (lat, long, llat, llong ) )+'km' ); + } ); +} diff --git a/css/main.scss b/css/main.scss index 399ae0fc19a98283c20314eceaad2af6e44a6fea..8b861b12dc15f4ff8db79284ce3a1ed1278cb424 100644 --- a/css/main.scss +++ b/css/main.scss @@ -187,3 +187,8 @@ lang { tags { color: darkgoldenrod; } + +.faircoin-price { + font-size:1rem; + color: goldenrod; +} diff --git a/script/get_orders.py b/script/get_orders.py index 7e96e81bdfbdd745563fa8099e7c520007b671f7..44279c874d2f034d1d4a8305d5b86b5e1040309d 100644 --- a/script/get_orders.py +++ b/script/get_orders.py @@ -32,6 +32,11 @@ Sources=load( s, Loader=Loader )['sources'] for source in Sources: + G=source.split('/') + gituser=G[-2] + gitrepo=G[-1] + giturl='/'.join(G[0:-2]) + contents = urlopen( source + '/raw/master/index.yml' ).read() O=load( contents, Loader=Loader ) @@ -42,6 +47,11 @@ for source in Sources: file = open('../_posts/'+Date + '-' +furl+'.md','w') file.write('---\n') file.write('layout: none\n') + file.write('git-repo: '+source+'\n') + file.write('git-profile: '+giturl + '/'+gituser+'\n' ) + file.write('order-title: '+furl+'\n' ) + file.write('latitude: '+str( O['latitude'] )+'\n' ) + file.write('longitude: '+str( O['longitude'] )+'\n' ) file.write(contents.decode("utf-8")) file.write('\n---') file.close()