Skip to content

Commit

Permalink
Merge pull request #461 from mitre-attack/reduce-artifact-size
Browse files Browse the repository at this point in the history
Reduce artifact size
  • Loading branch information
jondricek authored Oct 3, 2023
2 parents f609150 + 5551c69 commit f8150bd
Show file tree
Hide file tree
Showing 65 changed files with 411 additions and 359 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ attack-theme/templates/techniques
attack-theme/templates/website_build
attack-theme/templates/versions
attack-theme/static/scripts/settings.js
attack-theme/templates/general/sidebar-resources.html
content/
data/pelican_settings.json

Expand Down
16 changes: 16 additions & 0 deletions attack-theme/static/scripts/mobileview-datasources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This code is for creating a collapsable sidebar for the mobile view
let mediaQuery = window.matchMedia('(max-width: 47.9875rem)')

function mobileSidenav(e) {
if (e.matches) {
$('#sidebar-collapse').collapse('hide')
}
else{
$('#sidebar-collapse').collapse('show')
}
}
$(document).ready(function() {
mobileSidenav(mediaQuery)
});

mediaQuery.addEventListener('change', mobileSidenav)
19 changes: 1 addition & 18 deletions attack-theme/static/scripts/resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,4 @@ function resizeSidebar_mouseupHandler() {
}

resizer.addEventListener("mousedown", resizeSidebar_mousedownHandler);
}

//This code is for creating a collapsable sidebar for the mobile view
const mediaQuery = window.matchMedia('(max-width: 47.9875rem)')

function mobileSidenav(e) {
if (e.matches) {
$('#sidebar-collapse').collapse('hide')
}
else{
$('#sidebar-collapse').collapse('show')
}
}
$(document).ready(function() {
mobileSidenav(mediaQuery)
});

mediaQuery.addEventListener('change', mobileSidenav)
}
43 changes: 43 additions & 0 deletions attack-theme/static/scripts/sidebar-load-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
let mod_name = window.location.pathname.split("/")
let mod_entry = "/" + mod_name[1] + "/sidebar-" + mod_name[1]
if (mod_name.includes('contact')){
mod_entry = "/" + "resources/sidebar-resources"
}
$("#sidebars").load(mod_entry, function() {
let navElements = document.querySelectorAll('.sidenav-head > a');
let winlocation;
navElements.forEach(function(element){
if(!window.location.href.endsWith("/")){
winlocation = window.location.href + "/";
}
else{
winlocation = window.location.href
}
if(!element.href.endsWith("/")){
element.href = element.href + "/";
}
if(element.href == winlocation){
$(element.parentNode).addClass("active")
}});

//This code is for creating a collapsable sidebar for the mobile view
let mediaQuery = window.matchMedia('(max-width: 47.9875rem)')
function mobileSidenav(e) {
if (e.matches) {
$('#sidebar-collapse').collapse('hide')
}
else{
$('#sidebar-collapse').collapse('show')
}
}
$(document).ready(function() {
mobileSidenav(mediaQuery)
let sidenav = $(".sidenav-list");
let sidenav_active_elements = $(".sidenav .active");
if (sidenav_active_elements.length > 0) setTimeout(() => { //setTimeout gives bootstrap time to execute first
sidenav[0].scrollTop = sidenav_active_elements[0].offsetTop - 60;
});
});

mediaQuery.addEventListener('change', mobileSidenav)
});
9 changes: 9 additions & 0 deletions attack-theme/static/style/_layouts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ a {
}
}

.tables-mobile {
overflow-y: auto;
}

.table-bordered, .blog-post table, .changelog table {
&, & td, & th {
border: 1px solid border-color(body);
Expand Down Expand Up @@ -1051,6 +1055,11 @@ pre {

/******/

// how to display the sidebar
div#sidebars {
display: contents
}

/*Plus/Minus expand icons*/
// used in the expandable list items in the side navigation and in the expandable gray blocks in ATT&CKCON
.expand-icon {
Expand Down
6 changes: 2 additions & 4 deletions attack-theme/templates/general/attackcon-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
{% import 'macros/navigation.html' as navigation %}

{% block innerleft %}
<div id="v-tab" role="tablist" aria-orientation="vertical" class="h-100">
{{navigation.sidenav(RESOURCE_NAV, output_file)}}
</div>
<div id="sidebars"></div>
{% endblock %}

{% block innerright %}
Expand Down Expand Up @@ -117,5 +115,5 @@ <h2>Sponsors</h2>
{% block scripts %}
{{ super() }}
<!--SCRIPTS-->
<script src="/theme/scripts/navigation.js"></script>
<script src="/theme/scripts/sidebar-load-all.js"></script>
{% endblock %}
1 change: 0 additions & 1 deletion attack-theme/templates/general/base-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
<script src="/theme/scripts/site.js?{{ range(1, 9002) | random }}"></script>
<script src="/theme/scripts/settings.js?{{ range(1, 9002) | random }}"></script>
<script src="/theme/scripts/search_bundle.js"></script>
<script src="/theme/scripts/resizer.js"></script>
{% endblock %}
</body>
</html>
6 changes: 2 additions & 4 deletions attack-theme/templates/general/faq-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
{% import 'macros/navigation.html' as navigation %}

{% block innerleft %}
<div id="v-tab" role="tablist" aria-orientation="vertical" class="h-100">
{{navigation.sidenav(RESOURCE_NAV, output_file)}}
</div>
<div id="sidebars"></div>
{% endblock %}

{% block innerright %}
Expand Down Expand Up @@ -64,5 +62,5 @@ <h5>
{% block scripts %}
{{ super() }}
<!--SCRIPTS-->
<script src="/theme/scripts/navigation.js"></script>
<script src="/theme/scripts/sidebar-load-all.js"></script>
{% endblock %}
6 changes: 2 additions & 4 deletions attack-theme/templates/general/intro-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
{% import 'macros/navigation.html' as navigation %}

{% block innerleft %}
<div id="v-tab" role="tablist" aria-orientation="vertical" class="h-100">
{{navigation.sidenav(RESOURCE_NAV, output_file)}}
</div>
<div id="sidebars"></div>
{% endblock %}

{% block innerright %}
Expand All @@ -32,5 +30,5 @@ <h2>{{ page.title }}</h2>
{% block scripts %}
{{ super () }}
<script src="/theme/scripts/tables.js"></script>
<script src="/theme/scripts/navigation.js"></script>
<script src="/theme/scripts/sidebar-load-all.js"></script>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% set RESOURCE_NAV = ${RESOURCE_NAV} -%}
{% import 'macros/navigation.html' as navigation %}
<div id="v-tab" role="tablist" aria-orientation="vertical" class="h-100">
{{navigation.sidenav(RESOURCE_NAV, output_file)}}
</div>
{% block scripts %}
<!--SCRIPTS-->
<script src="/theme/scripts/navigation.js"></script>
{% endblock %}
9 changes: 9 additions & 0 deletions attack-theme/templates/general/sidebar-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% import 'macros/navigation.html' as navigation %}
{% set parsed = page.data | from_json %}
<div id="v-tab" role="tablist" aria-orientation="vertical" class="h-100">
{{ navigation.sidenav(parsed.menu, output_file) }}
</div>
{% block scripts %}
<!--SCRIPTS-->
<script src="/theme/scripts/navigation.js"></script>
{% endblock %}
7 changes: 6 additions & 1 deletion attack-theme/templates/general/two-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block left %}
{{ super() }}
<div class="sidebar nav sticky-top flex-column pr-0 pt-4 pb-3 pl-3" id="v-tab" role="tablist" aria-orientation="vertical">
<div class="resizer"></div>
<div class="resizer" id="resizer"></div>
{% block innerleft %}
{% endblock %}
</div>
Expand All @@ -22,3 +22,8 @@
{% endblock %}

{% endblock %}
{% block scripts %}
{{ super() }}
<!--SCRIPTS-->
<script src="/theme/scripts/resizer.js"></script>
{% endblock %}
2 changes: 2 additions & 0 deletions attack-theme/templates/macros/datasource_table.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% import 'macros/clean_output.html' as clean_output %}

{% macro datasource_table(datasources, show_descriptions, citations=None) %}
<div class="tables-mobile">
<table class="table datasources-table table-bordered">
<thead>
<tr>
Expand Down Expand Up @@ -50,4 +51,5 @@
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
6 changes: 2 additions & 4 deletions attack-theme/templates/macros/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
-->
{% macro sidenav(root, output_file, filter=False) %}
<div class="sidenav-wrapper">
<div class="heading" data-toggle="collapse" data-target="#sidebar-collapse" id="v-home-tab" aria-selected="false">{{root.name | upper}}
<div class="heading" data-toggle="collapse" data-target="#sidebar-collapse" id="v-home-tab" aria-expanded="true" aria-controls="#sidebar-collapse" aria-selected="false">{{root.name | upper}}
<i class="fa fa-fw fa-chevron-down"></i>
<i class="fa fa-fw fa-chevron-up"></i>
</div>
Expand All @@ -41,8 +41,7 @@
</div>
{% endif %}
<br class="br-mobile">
<div class="collapse show" id="sidebar-collapse">
<div class="sidenav-list">
<div class="sidenav-list collapse show" id="sidebar-collapse" aria-labelledby="v-home-tab">
{# "overview" link as first item in list if root.path exists #}
{% if root.path %}
{{ sidenav_helper("0", {"name": "Overview", "id": "0", "path": root.path, "children": []}, output_file) }}
Expand All @@ -52,7 +51,6 @@
{% endfor %}
</div>
</div>
</div>
{% endmacro %}

<!-- recusive helper for sidenav -->
Expand Down
2 changes: 2 additions & 0 deletions attack-theme/templates/macros/techniques_used.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% if title %}
<h2 class="pt-3 mb-2" id="techniques">{{title}}</h2>
{% endif %}
<div class="tables-mobile">
<table class="table techniques-used background table-bordered">
<thead>
<tr>
Expand Down Expand Up @@ -133,4 +134,5 @@ <h2 class="pt-3 mb-2" id="techniques">{{title}}</h2>
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
6 changes: 2 additions & 4 deletions modules/benefactors/templates/benefactors.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
{% import 'macros/navigation.html' as navigation %}

{% block innerleft %}
<div id="v-tab" role="tablist" aria-orientation="vertical" class="h-100">
{{navigation.sidenav(RESOURCE_NAV, output_file)}}
</div>
<div id="sidebars"></div>
{% endblock %}

{% block innerright %}
Expand All @@ -30,5 +28,5 @@ <h2>Benefactors</h2>
{% block scripts %}
{{ super () }}
<script src="/theme/scripts/tables.js"></script>
<script src="/theme/scripts/navigation.js"></script>
<script src="/theme/scripts/sidebar-load-all.js"></script>
{% endblock %}
15 changes: 14 additions & 1 deletion modules/campaigns/campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def generate_markdown_files():
data["campaigns_list_len"] = str(len(campaign_list_no_deprecated_revoked))

subs = campaigns_config.campaign_index_md + json.dumps(data)

generate_sidebar_campaigns(side_menu_data)
with open(
os.path.join(campaigns_config.campaign_markdown_path, "overview.md"), "w", encoding="utf8"
) as md_file:
Expand Down Expand Up @@ -308,3 +308,16 @@ def get_software_table_data(campaign, reference_list):
software_data = [software_list[item] for item in software_list]
software_data = sorted(software_data, key=lambda k: k["name"].lower())
return software_data

def generate_sidebar_campaigns(side_menu_data):
"""Responsible for generating the sidebar for the campaigns pages."""
logger.info("Generating campaigns sidebar")
data = {}
data["menu"] = side_menu_data

# Sidebar Overview
sidebar_campaigns_md = campaigns_config.sidebar_campaigns_md + json.dumps(data)

# write markdown to file
with open(os.path.join(campaigns_config.campaign_markdown_path, "sidebar_campaigns.md"), "w", encoding="utf8") as md_file:
md_file.write(sidebar_campaigns_md)
7 changes: 7 additions & 0 deletions modules/campaigns/campaigns_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@
campaigns_templates_path = "modules/campaigns/templates/"

campaigns_redirection_location = "modules/campaigns/campaigns_redirections.json"

sidebar_campaigns_md = (
"Title: Campaigns Sidebar\n"
"Template: general/sidebar-template \n"
"save_as: campaigns/sidebar-campaigns/index.html\n"
"data: "
)
Loading

0 comments on commit f8150bd

Please sign in to comment.