Jekyll页面特定的CSS

时间:2018-08-02 07:03:43

标签: css jekyll

我是第一次使用Jekyll建立一个网站,到目前为止,它确实很棒。

我的问题是:我希望能够向网站的特定页面添加特定的CSS。

问题是:是否有一种聪明的方法可以在特定页面上添加一些代码行,也许使用YAML?”

在使用Jekyll之前,我曾经在<head>中链接一个单独的.css文件,如下所示:

<link rel="stylesheet" href="/style.css">       # main stylesheet
<link rel="stylesheet" href="/page/style.css">  # secondary stylesheet


更新#1

我找到了此文档https://jekyllrb.com/docs/includes/#using-variables-names-for-the-include-file
它似乎完成了与我正在寻找的类似的事情。
唯一的问题是(由于我设置模板的方式)CSS最终被包含在<body>标记中。似乎一切正常。

1 个答案:

答案 0 :(得分:3)

您的问题有一个聪明的答案:使用前题变量定义用于特定页面的样式。

public class BookingHistoryFragment extends Fragment {

  String parsed; //Defined Globally
  private TextView bookingHistoryTV;
  private RequestQueue mQueue;

  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 
  @Nullable Bundle savedInstanceState) {


  View view = inflater.inflate(R.layout.fragment_booking_history, container, false);
  bookingHistoryTV = view.findViewById(R.id.bookingHistoryTV);
  jsonParse();

  return inflater.inflate(R.layout.fragment_booking_history, container, false);
  }

  private void jsonParse() {
  String url = "http://178.128.166.68/getBookingHistory.php";

  JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
        new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    JSONArray jsonArray = response.getJSONArray("bookingHistory");

                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject bookingHistory = jsonArray.getJSONObject(i);

                        String fromLocality = 
                         bookingHistory.getString("fromLocality");
                        String toLocality = bookingHistory.getString("toLocality");
                        double cost = bookingHistory.getDouble("cost");
                        String date = bookingHistory.getString("date");

                        parsed = fromLocality + " | " + toLocality + " | " + String.valueOf(cost) + " | " + date + "\n\n";
                    }

                  bookingHistoryTV.setText(parsed); //setText outside of For Loop

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        error.printStackTrace();
    }
});

  //creating a request queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);

 //adding the string request to request queue
    mQueue.add(request);
   }
 }

布局/default.html

---
title:  any page
style:  one         # defines body main class
layout: default
---

您的CSS

<body class="{% if page.style %}{{ page.style }} {% endif %}">
...
相关问题