forked from mirrors/treebird
Show hashtags
Search is now complete FossilOrigin-Name: f179685db72b1e1cb6be3a9c450a83e717c18c4601a9d00be52bcbda46698e0f
This commit is contained in:
parent
dbdcc2a8d9
commit
bf48f29ce2
7 changed files with 134 additions and 1 deletions
6
Makefile
6
Makefile
|
@ -102,6 +102,12 @@ $(PAGES_DIR)/favourites_page.chtml: $(PAGES_DIR)/favourites_page.html
|
|||
./filec $< data_favourites_page_html > $@
|
||||
$(PAGES_DIR)/account_stub.chtml: $(PAGES_DIR)/account_stub.html
|
||||
./filec $< data_account_stub_html > $@
|
||||
$(PAGES_DIR)/hashtag.chtml: $(PAGES_DIR)/hashtag.html
|
||||
./filec $< data_hashtag_html > $@
|
||||
$(PAGES_DIR)/hashtag_page.chtml: $(PAGES_DIR)/hashtag_page.html
|
||||
./filec $< data_hashtag_page_html > $@
|
||||
$(PAGES_DIR)/hashtag_statistics.chtml: $(PAGES_DIR)/hashtag_statistics.html
|
||||
./filec $< data_hashtag_statistics_html > $@
|
||||
|
||||
$(MASTODONT_DIR):
|
||||
git clone $(MASTODONT_URL) || true
|
||||
|
|
57
src/hashtag.c
Normal file
57
src/hashtag.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Treebird - Lightweight frontend for Pleroma
|
||||
* Copyright (C) 2022 Nekobit
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "hashtag.h"
|
||||
#include "string_helpers.h"
|
||||
#include "easprintf.h"
|
||||
|
||||
// Pages
|
||||
#include "../static/hashtag.chtml"
|
||||
#include "../static/hashtag_page.chtml"
|
||||
#include "../static/hashtag_statistics.chtml"
|
||||
|
||||
#define TAG_SIZE_INITIAL 12
|
||||
|
||||
char* construct_hashtag(struct mstdnt_tag* hashtag, int* size)
|
||||
{
|
||||
char* hashtag_html;
|
||||
|
||||
// Lol!
|
||||
unsigned hash_size = TAG_SIZE_INITIAL +
|
||||
((unsigned)(
|
||||
(hashtag->history && hashtag->history_len >= 1 ?
|
||||
hashtag->history[0].uses : 0) + 4
|
||||
/4)*2);
|
||||
|
||||
size_t s = easprintf(&hashtag_html, data_hashtag_html,
|
||||
hash_size, hashtag->name);
|
||||
|
||||
if (size) *size = s;
|
||||
return hashtag_html;
|
||||
}
|
||||
|
||||
static char* construct_hashtag_voidwrap(void* passed, size_t index, int* res)
|
||||
{
|
||||
return construct_hashtag((struct mstdnt_tag*)passed + index, res);
|
||||
}
|
||||
char* construct_hashtags(struct mstdnt_tag* hashtags, size_t size, size_t* ret_size)
|
||||
{
|
||||
if (!(hashtags && size)) return NULL;
|
||||
return construct_func_strings(construct_hashtag_voidwrap, hashtags, size, ret_size);
|
||||
}
|
||||
|
27
src/hashtag.h
Normal file
27
src/hashtag.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Treebird - Lightweight frontend for Pleroma
|
||||
* Copyright (C) 2022 Nekobit
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HASHTAG_H
|
||||
#define HASHTAG_H
|
||||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
|
||||
char* construct_hashtag(struct mstdnt_tag* hashtag, int* size);
|
||||
char* construct_hashtags(struct mstdnt_tag* hashtags, size_t size, size_t* ret_size);
|
||||
|
||||
#endif /* HASHTAG_H */
|
35
src/search.c
35
src/search.c
|
@ -23,6 +23,7 @@
|
|||
#include "string_helpers.h"
|
||||
#include "base_page.h"
|
||||
#include "status.h"
|
||||
#include "hashtag.h"
|
||||
#include "error.h"
|
||||
#include "account.h"
|
||||
|
||||
|
@ -137,5 +138,37 @@ void content_search_accounts(struct session* ssn, mastodont_t* api, char** data)
|
|||
|
||||
void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data)
|
||||
{
|
||||
search_page(ssn, api, SEARCH_HASHTAGS, "hashtags");
|
||||
char* tags_html;
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
struct mstdnt_search_args args = {
|
||||
.account_id = NULL,
|
||||
.type = MSTDNT_SEARCH_HASHTAGS,
|
||||
.resolve = 0,
|
||||
.following = 0,
|
||||
.with_relationships = 0,
|
||||
.max_id = NULL,
|
||||
.min_id = NULL,
|
||||
.since_id = NULL,
|
||||
.offset = 0,
|
||||
.limit = 20,
|
||||
};
|
||||
struct mstdnt_search_results results = { 0 };
|
||||
|
||||
if (mastodont_search(api,
|
||||
ssn->query.query,
|
||||
&storage,
|
||||
&args,
|
||||
&results) == 0)
|
||||
{
|
||||
tags_html = construct_hashtags(results.tags, results.tags_len, NULL);
|
||||
if (!tags_html)
|
||||
tags_html = construct_error("No hashtags", E_ERROR, 1, NULL);
|
||||
}
|
||||
else
|
||||
tags_html = construct_error("An error occured.", E_ERROR, 1, NULL);
|
||||
|
||||
search_page(ssn, api, SEARCH_HASHTAGS, STR_NULL_EMPTY(tags_html));
|
||||
|
||||
if (tags_html) free(tags_html);
|
||||
// TODO cleanup shit
|
||||
}
|
||||
|
|
1
static/hashtag.html
Normal file
1
static/hashtag.html
Normal file
|
@ -0,0 +1 @@
|
|||
<span style="font-size: %upx;" class="hashtag-item">#%s</span>
|
8
static/hashtag_page.html
Normal file
8
static/hashtag_page.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<div class="simple-page">
|
||||
<h1>Hashtag - #%s</h1>
|
||||
</div>
|
||||
%s
|
||||
<div class="hashtags-container">
|
||||
%s
|
||||
</div>
|
||||
%s
|
1
static/hashtag_statistics.html
Normal file
1
static/hashtag_statistics.html
Normal file
|
@ -0,0 +1 @@
|
|||
<div>[STATISTICS]</div>
|
Loading…
Reference in a new issue