diff --git a/search/templates/cosmos/header.html b/search/templates/cosmos/header.html index 58c1e79..e94c57f 100644 --- a/search/templates/cosmos/header.html +++ b/search/templates/cosmos/header.html @@ -83,6 +83,7 @@ GitHub cosmos calculator + tags
diff --git a/search/templates/cosmos/index.html b/search/templates/cosmos/index.html index 45530e1..113d127 100644 --- a/search/templates/cosmos/index.html +++ b/search/templates/cosmos/index.html @@ -1,8 +1,20 @@ {% extends 'cosmos/header.html' %} {% block body %} {% load random_numbers %} - + + +
+

Welcome to cosmos-search


diff --git a/search/templates/cosmos/tags.html b/search/templates/cosmos/tags.html new file mode 100644 index 0000000..1f8ad98 --- /dev/null +++ b/search/templates/cosmos/tags.html @@ -0,0 +1,41 @@ + + +{% extends 'cosmos/header.html' %} +{% block body %} + + + + + + + +

Tags

+
+ +A tag is a keyword or label that categorizes your search query with other, similar queries. Users can use these tags in exploring new topics and continue browsing without prior knowledge. + +

+ +


+ +{% endblock %} + diff --git a/search/urls.py b/search/urls.py index 89a441b..1d396c5 100644 --- a/search/urls.py +++ b/search/urls.py @@ -3,6 +3,7 @@ urlpatterns = [ url(r'^$', views.index, name='index'), + url(r'^tags/', views.tags, name='tags'), url(r'^query/', views.query, name='query'), url(r'^display', views.display, name='display'), url(r'^calculator/', views.calculator, name='calculator'), diff --git a/search/views.py b/search/views.py index 14bfd00..ce87dc4 100644 --- a/search/views.py +++ b/search/views.py @@ -14,7 +14,16 @@ # Create your views here +# Tags page for users +def tags(request): + f = open(settings.TAGS_JSON, 'r') + jsonL = sorted(list(json.load(f))) + args = {"tags": jsonL} + return render(request, 'cosmos/tags.html', args) + # To prefill the searchbar + + def get_random_tag(): jsonFile = open(settings.TAGS_JSON, 'r') algo_list = json.load(jsonFile) @@ -50,12 +59,15 @@ def searchSuggestion(request): def index(request): + randomTags = [] + for i in range(4): + randomTags.append(get_random_tag()) query = get_random_tag() algo = searchSuggestion(request) if request.is_ajax(): mimetype = 'application/json' return HttpResponse(algo, mimetype) - return render(request, 'cosmos/index.html', {'query': query}) + return render(request, 'cosmos/index.html', {'query': query, 'random': randomTags}) # Handlers for error pages @@ -158,20 +170,20 @@ def code_search(request, query): else: d = folder_list[-3] + '/' for i, j in data.items(): - if d in i: - if query not in i: - only_contents_md = True - for f in j: - if not is_file_extension_ignored(f): - only_contents_md = False - break - if only_contents_md: - continue - p = i - p = p.split('/') - l = p[len(p) - 1] - codes['recommendations'].append( - {'recpath': i, 'recdirs': p, 'last': l}) + if d in i: + if query not in i: + only_contents_md = True + for f in j: + if not is_file_extension_ignored(f): + only_contents_md = False + break + if only_contents_md: + continue + p = i + p = p.split('/') + l = p[len(p) - 1] + codes['recommendations'].append( + {'recpath': i, 'recdirs': p, 'last': l}) shuffle(codes['recommendations']) codes['recommendations'] = codes['recommendations'][:5]