May I ask, how can I call upon the information of the article's author on the content page of the article?
โ Dev ๐ 2023-09-17 ๐ค Ryza ๐๏ธ 117What I mean is, if the author information is to be displayed on the right side, it needs to be added to the layout page, but how should I call it? Should I call it by checking the โiidโ like we do for the โinnโ information?
๐ท๏ธ userYouโd better see the askama doc first.
In layout we define a block box
https://github.com/freedit-org/freedit/blob/4897ae17ecda59ea60f306e17ee2896b9b14e71b/templates/layout.html#L134-L135. You can see its location in block aside
. So just add a block in
{% block box %} <div class="box"> <div class="level-item has-text-centered"> <figure class="image is-128x128"> <a href="/user/{{post.uid}}"><img class="is-rounded" src="/static/avatars/{{post.uid}}.png"></a> </figure> </div> </div> {% endblock %}
Ryza 2023-09-18 ๐ ๐ [op]
@freedit Itโs my mistake. I mistook the code for calling โInnโ in inn.html as code from layout.html. Because there is code in inn.html that checks โ{% if iid > 0 %}โ, I mistakenly thought it also needed to check if itโs the authorโs issue. Haha, Iโm really sorry.
Ryza 2023-09-18 ๐ ๐ [op]
Okay, I give up on displaying the author information on the right side. When I want to implement the follow and unfollow functionality on the article page, Iโll need to access data from the userโs page. So, Iโll need to re-implement the follow feature in inn.rs. Perhaps itโs possible to consolidate all the data into a single data source for easier access. Iโm not sure if this approach will cause any other issues.
Ryza 2023-09-18 ๐ ๐ [op]
@
freedit I have now added page views to the post_list, and I use โlet pageview = incr_id(&DB.open_tree(โpost_pageviewsโ)?, u32_to_ivec(*pid))?;โ to implement it. I found that when using โincr_id,โ every time I refresh the homepage, it increases the page views for all articles. So, after removing the โincr_idโ function, how can I just query the page views?
I attempted to query using โlet pageview = get_one(db, โpost_pageviewsโ, *pid)?;โ, but the returned result is empty.
Youโd better install rust analyzer to make your life easier.
Ryza 2023-09-18 ๐ 1 ๐ [op]
@freedit Thank you for your help. I implemented it like this:
let tree_name = "post_pageviews"; let tree = DB.open_tree(tree_name)?; let query_key = u32_to_ivec(*pid); let pageview = tree .get(&query_key)? .map(|count_bytes| ivec_to_u32(&count_bytes)) .unwrap_or(0);
Although the code may not be elegant, it can successfully retrieve the page views. Haha ๐