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    ๐Ÿ‘๏ธ 117      


What 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?

๐Ÿท๏ธ user

Ryza    2023-09-17 ๐Ÿ‘ ๐Ÿ‘Ž [op]

All the right side information is in [aside class=โ€œcolumn is-one-quarterโ€] in the layout page, so itโ€™s a bit hard for me to try to add a new box in the post content page, any good way to do it?


freedit    2023-09-17 ๐Ÿ‘ ๐Ÿ‘Ž

Youโ€™d better see the askama doc first.

In layout we define a block box 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>
{% 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 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.


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
    .map(|count_bytes| ivec_to_u32(&count_bytes))

Although the code may not be elegant, it can successfully retrieve the page views. Haha ๐Ÿ˜„


Ryza    2023-09-18 ๐Ÿ‘ ๐Ÿ‘Ž [op]

#8 thx I use tailwind css, it works very well with a rich set of components and fast classes.