~sircmpwn/core.sr.ht

db099290d919a7ea3d1b241ee76ebaecc0b705ec — Drew DeVault 1 year, 5 months ago 16834a8 0.60.0
Overhaul site navigation
4 files changed, 37 insertions(+), 43 deletions(-)

M srht/flask.py
M srht/scss/base.scss
M srht/scss/nav.scss
M srht/templates/nav.html
M srht/flask.py => srht/flask.py +1 -38
@@ 378,13 378,6 @@ class SrhtFlask(Flask):
                        max_age=60 * 60 * 24 * 365)

        path = request.path
        if hasattr(self, "network_prefs") and not path.startswith("/api"):
            for key, value in self.network_prefs.items():
                response.set_cookie(f"{key}-preference",
                        json.dumps(value),
                        domain=global_domain,
                        max_age=60 * 60 * 24 * 365)

        return response

    def static_resource(self, path):


@@ 403,34 396,4 @@ class SrhtFlask(Flask):
        return self.static_cache[path]

    def get_network(self):
        sites = [s for s in config if s.endswith(".sr.ht")]
        categories = dict()
        for site in sites:
            if "servicecategory" in config[site]:
                cat = cfg(site, "servicecategory")
                members = categories.setdefault(cat, list())
                categories[cat].append(site)
        if not hasattr(self, "network_prefs") and len(categories) != 0:
            self.network_prefs = {}
        for cat, members in categories.items():
            prefs = { site: cfgi(site, "serviceweight") for site in members }
            try:
                prefs.update(json.loads(
                    request.cookies.get(f"{cat}-preference", "{}")))
                assert all(isinstance(k, str) for k in prefs.keys())
                assert all(isinstance(v, int) for v in prefs.values())
            except:
                prefs = { site: 0 for site in members }
            if self.site in members:
                prefs[self.site] += 1
                self.network_prefs[cat] = {k: v for k, v in prefs.items()}
                prefs[self.site] = 10000000
            else:
                self.network_prefs[cat] = prefs
            prefs = sorted(((k, v) for k, v in prefs.items()),
                    key=lambda t: t[1], reverse=True)
            sites = [
                site for site in sites
                if site not in members or prefs[0][0] == site
            ]
        return sites
        return [s for s in config if s.endswith(".sr.ht")]

M srht/scss/base.scss => srht/scss/base.scss +3 -4
@@ 245,10 245,9 @@ section {
  line-height: 1.6;
}

.navbar-light {
  .navbar-brand {
    color: $black;
  }
.btn-sm {
  font-size: 0.95rem;
  padding: 0 0.75rem;
}

.alert {

M srht/scss/nav.scss => srht/scss/nav.scss +21 -1
@@ 15,10 15,17 @@
          padding-left: 0;
        }
      }

    }
  }

  .nav-link:hover {
    text-decoration: underline;
  }

  .navbar-brand:hover {
    text-decoration: underline;
  }

  .navbar-text {
    color: $black;



@@ 28,6 35,19 @@
  }
}

.navbar-light .navbar-brand {
  color: $link-color;

  .icon {
    position: relative;
    top: 1px;
  }

  &:hover {
    color: darken($link-color, 15);
  }
}

.nav-tabs {
  padding-left: 1rem;
  margin-bottom: 0.5rem;

M srht/templates/nav.html => srht/templates/nav.html +12 -0
@@ 1,16 1,28 @@
{% if "hub.sr.ht" in network %}
<a class="navbar-brand" href="{{get_origin("hub.sr.ht", external=True)}}">
  {{icon('circle', cls='text-muted')}}
  {{site_name}}
</a>
{% else %}
<a class="navbar-brand" href="/">
  {{icon('circle', cls='text-muted')}}
  {{site_name}}
  <span class="text-danger">{{site.split(".")[0]}}</span>
</a>
{% endif %}
<ul class="navbar-nav">
  {% if current_user %}
  {% for _site in network %}

  {% if _site != "hub.sr.ht" %}
  <li class="nav-item {{'active' if _site == site else ''}}">
    <a
      class="nav-link"
      href="{{get_origin(_site, external=True)}}"
    >{{_site.split(".")[0]}}</a>
  </li>
  {% endif %}

  {% endfor %}
  {% endif %}
</ul>