templates.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. .. _simple theme templates:
  2. ======================
  3. Simple Theme Templates
  4. ======================
  5. The simple template is complex, it consists of many different elements and also
  6. uses macros and include statements. The following is a rough overview that we
  7. would like to give the developerat hand, details must still be taken from the
  8. :origin:`sources <searx/templates/simple/>`.
  9. A :ref:`result item <result types>` can be of different media types. The media
  10. type of a result is defined by the :py:obj:`result_type.Result.template`. To
  11. set another media-type as :ref:`template default`, the field ``template``
  12. in the result item must be set to the desired type.
  13. .. contents:: Contents
  14. :depth: 2
  15. :local:
  16. :backlinks: entry
  17. .. _result template macros:
  18. Result template macros
  19. ======================
  20. .. _macro result_header:
  21. ``result_header``
  22. -----------------
  23. Execpt ``image.html`` and some others this macro is used in nearly all result
  24. types in the :ref:`main result list`.
  25. Fields used in the template :origin:`macro result_header
  26. <searx/templates/simple/macros.html>`:
  27. url : :py:class:`str`
  28. Link URL of the result item.
  29. title : :py:class:`str`
  30. Link title of the result item.
  31. img_src, thumbnail : :py:class:`str`
  32. URL of a image or thumbnail that is displayed in the result item.
  33. .. _macro result_sub_header:
  34. ``result_sub_header``
  35. ---------------------
  36. Execpt ``image.html`` and some others this macro is used in nearly all result
  37. types in the :ref:`main result list`.
  38. Fields used in the template :origin:`macro result_sub_header
  39. <searx/templates/simple/macros.html>`:
  40. publishedDate : :py:obj:`datetime.datetime`
  41. The date on which the object was published.
  42. length: :py:obj:`time.struct_time`
  43. Playing duration in seconds.
  44. views: :py:class:`str`
  45. View count in humanized number format.
  46. author : :py:class:`str`
  47. Author of the title.
  48. metadata : :py:class:`str`
  49. Miscellaneous metadata.
  50. .. _engine_data:
  51. ``engine_data_form``
  52. --------------------
  53. The ``engine_data_form`` macro is used in :origin:`results,html
  54. <searx/templates/simple/results.html>` in a HTML ``<form/>`` element. The
  55. intention of this macro is to pass data of a engine from one :py:obj:`response
  56. <searx.engines.demo_online.response>` to the :py:obj:`searx.search.SearchQuery`
  57. of the next :py:obj:`request <searx.engines.demo_online.request>`.
  58. To pass data, engine's response handler can append result items of typ
  59. ``engine_data``. This is by example used to pass a token from the response to
  60. the next request:
  61. .. code:: python
  62. def response(resp):
  63. ...
  64. results.append({
  65. 'engine_data': token,
  66. 'key': 'next_page_token',
  67. })
  68. ...
  69. return results
  70. def request(query, params):
  71. page_token = params['engine_data'].get('next_page_token')
  72. .. _main result list:
  73. Main Result List
  74. ================
  75. The **media types** of the **main result type** are the template files in
  76. the :origin:`result_templates <searx/templates/simple/result_templates>`.
  77. .. _template default:
  78. ``default.html``
  79. ----------------
  80. Displays result fields from:
  81. - :ref:`macro result_header` and
  82. - :ref:`macro result_sub_header`
  83. Additional fields used in the :origin:`default.html
  84. <searx/templates/simple/result_templates/default.html>`:
  85. content : :py:class:`str`
  86. General text of the result item.
  87. iframe_src : :py:class:`str`
  88. URL of an embedded ``<iframe>`` / the frame is collapsible.
  89. audio_src : uri,
  90. URL of an embedded ``<audio controls>``.
  91. .. _template images:
  92. ``images.html``
  93. ---------------
  94. The images are displayed as small thumbnails in the main results list.
  95. title : :py:class:`str`
  96. Title of the image.
  97. thumbnail_src : :py:class:`str`
  98. URL of a preview of the image.
  99. resolution :py:class:`str`
  100. The resolution of the image (e.g. ``1920 x 1080`` pixel)
  101. Image labels
  102. ~~~~~~~~~~~~
  103. Clicking on the preview opens a gallery view in which all further metadata for
  104. the image is displayed. Addition fields used in the :origin:`images.html
  105. <searx/templates/simple/result_templates/images.html>`:
  106. img_src : :py:class:`str`
  107. URL of the full size image.
  108. content: :py:class:`str`
  109. Description of the image.
  110. author: :py:class:`str`
  111. Name of the author of the image.
  112. img_format : :py:class:`str`
  113. The format of the image (e.g. ``png``).
  114. source : :py:class:`str`
  115. Source of the image.
  116. filesize: :py:class:`str`
  117. Size of bytes in :py:obj:`human readable <searx.humanize_bytes>` notation
  118. (e.g. ``MB`` for 1024 \* 1024 Bytes filesize).
  119. url : :py:class:`str`
  120. URL of the page from where the images comes from (source).
  121. .. _template videos:
  122. ``videos.html``
  123. ---------------
  124. Displays result fields from:
  125. - :ref:`macro result_header` and
  126. - :ref:`macro result_sub_header`
  127. Additional fields used in the :origin:`videos.html
  128. <searx/templates/simple/result_templates/videos.html>`:
  129. iframe_src : :py:class:`str`
  130. URL of an embedded ``<iframe>`` / the frame is collapsible.
  131. The videos are displayed as small thumbnails in the main results list, there
  132. is an additional button to collaps/open the embeded video.
  133. content : :py:class:`str`
  134. Description of the code fragment.
  135. .. _template torrent:
  136. ``torrent.html``
  137. ----------------
  138. .. _magnet link: https://en.wikipedia.org/wiki/Magnet_URI_scheme
  139. .. _torrent file: https://en.wikipedia.org/wiki/Torrent_file
  140. Displays result fields from:
  141. - :ref:`macro result_header` and
  142. - :ref:`macro result_sub_header`
  143. Additional fields used in the :origin:`torrent.html
  144. <searx/templates/simple/result_templates/torrent.html>`:
  145. magnetlink:
  146. URL of the `magnet link`_.
  147. torrentfile
  148. URL of the `torrent file`_.
  149. seed : ``int``
  150. Number of seeders.
  151. leech : ``int``
  152. Number of leecher
  153. filesize : ``int``
  154. Size in Bytes (rendered to human readable unit of measurement).
  155. files : ``int``
  156. Number of files.
  157. .. _template map:
  158. ``map.html``
  159. ------------
  160. .. _GeoJSON: https://en.wikipedia.org/wiki/GeoJSON
  161. .. _Leaflet: https://github.com/Leaflet/Leaflet
  162. .. _bbox: https://wiki.openstreetmap.org/wiki/Bounding_Box
  163. .. _HTMLElement.dataset: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset
  164. .. _Nominatim: https://nominatim.org/release-docs/latest/
  165. .. _Lookup: https://nominatim.org/release-docs/latest/api/Lookup/
  166. .. _place_id is not a persistent id:
  167. https://nominatim.org/release-docs/latest/api/Output/#place_id-is-not-a-persistent-id
  168. .. _perma_id: https://wiki.openstreetmap.org/wiki/Permanent_ID
  169. .. _country code: https://wiki.openstreetmap.org/wiki/Country_code
  170. Displays result fields from:
  171. - :ref:`macro result_header` and
  172. - :ref:`macro result_sub_header`
  173. Additional fields used in the :origin:`map.html
  174. <searx/templates/simple/result_templates/map.html>`:
  175. content : :py:class:`str`
  176. Description of the item.
  177. address_label : :py:class:`str`
  178. Label of the address / default ``_('address')``.
  179. geojson : GeoJSON_
  180. Geometries mapped to HTMLElement.dataset_ (``data-map-geojson``) and used by
  181. Leaflet_.
  182. boundingbox : ``[ min-lon, min-lat, max-lon, max-lat]``
  183. A bbox_ area defined by min longitude , min latitude , max longitude and max
  184. latitude. The bounding box is mapped to HTMLElement.dataset_
  185. (``data-map-boundingbox``) and is used by Leaflet_.
  186. longitude, latitude : :py:class:`str`
  187. Geographical coordinates, mapped to HTMLElement.dataset_ (``data-map-lon``,
  188. ``data-map-lat``) and is used by Leaflet_.
  189. address : ``{...}``
  190. A dicticonary with the address data:
  191. .. code:: python
  192. address = {
  193. 'name' : str, # name of object
  194. 'road' : str, # street name of object
  195. 'house_number' : str, # house number of object
  196. 'postcode' : str, # postcode of object
  197. 'country' : str, # country of object
  198. 'country_code' : str,
  199. 'locality' : str,
  200. }
  201. country_code : :py:class:`str`
  202. `Country code`_ of the object.
  203. locality : :py:class:`str`
  204. The name of the city, town, township, village, borough, etc. in which this
  205. object is located.
  206. links : ``[link1, link2, ...]``
  207. A list of links with labels:
  208. .. code:: python
  209. links.append({
  210. 'label' : str,
  211. 'url' : str,
  212. 'url_label' : str, # set by some engines but unused (oscar)
  213. })
  214. data : ``[data1, data2, ...]``
  215. A list of additional data, shown in two columns and containing a label and
  216. value.
  217. .. code:: python
  218. data.append({
  219. 'label' : str,
  220. 'value' : str,
  221. 'key' : str, # set by some engines but unused
  222. })
  223. type : :py:class:`str` # set by some engines but unused (oscar)
  224. Tag label from :ref:`OSM_KEYS_TAGS['tags'] <update_osm_keys_tags.py>`.
  225. type_icon : :py:class:`str` # set by some engines but unused (oscar)
  226. Type's icon.
  227. osm : ``{...}``
  228. OSM-type and OSM-ID, can be used to Lookup_ OSM data (Nominatim_). There is
  229. also a discussion about "`place_id is not a persistent id`_" and the
  230. perma_id_.
  231. .. code:: python
  232. osm = {
  233. 'type': str,
  234. 'id': str,
  235. }
  236. type : :py:class:`str`
  237. Type of osm-object (if OSM-Result).
  238. id :
  239. ID of osm-object (if OSM-Result).
  240. .. hint::
  241. The ``osm`` property is set by engine ``openstreetmap.py``, but it is not
  242. used in the ``map.html`` template yet.
  243. .. _template paper:
  244. ``paper.html``
  245. --------------
  246. .. _BibTeX format: https://www.bibtex.com/g/bibtex-format/
  247. .. _BibTeX field types: https://en.wikipedia.org/wiki/BibTeX#Field_types
  248. Displays result fields from:
  249. - :ref:`macro result_header`
  250. Additional fields used in the :origin:`paper.html
  251. <searx/templates/simple/result_templates/paper.html>`:
  252. content : :py:class:`str`
  253. An abstract or excerpt from the document.
  254. comments : :py:class:`str`
  255. Free text display in italic below the content.
  256. tags : :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  257. Free tag list.
  258. type : :py:class:`str`
  259. Short description of medium type, e.g. *book*, *pdf* or *html* ...
  260. authors : :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  261. List of authors of the work (authors with a "s" suffix, the "author" is in the
  262. :ref:`macro result_sub_header`).
  263. editor : :py:class:`str`
  264. Editor of the book/paper.
  265. publisher : :py:class:`str`
  266. Name of the publisher.
  267. journal : :py:class:`str`
  268. Name of the journal or magazine the article was published in.
  269. volume : :py:class:`str`
  270. Volume number.
  271. pages : :py:class:`str`
  272. Page range where the article is.
  273. number : :py:class:`str`
  274. Number of the report or the issue number for a journal article.
  275. doi : :py:class:`str`
  276. DOI number (like ``10.1038/d41586-018-07848-2``).
  277. issn : :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  278. ISSN number like ``1476-4687``
  279. isbn : :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  280. ISBN number like ``9780201896831``
  281. pdf_url : :py:class:`str`
  282. URL to the full article, the PDF version
  283. html_url : :py:class:`str`
  284. URL to full article, HTML version
  285. .. _template packages:
  286. ``packages``
  287. ------------
  288. Displays result fields from:
  289. - :ref:`macro result_header`
  290. Additional fields used in the :origin:`packages.html
  291. <searx/templates/simple/result_templates/packages.html>`:
  292. package_name : :py:class:`str`
  293. The name of the package.
  294. version : :py:class:`str`
  295. The current version of the package.
  296. maintainer : :py:class:`str`
  297. The maintainer or author of the project.
  298. publishedDate : :py:class:`datetime <datetime.datetime>`
  299. Date of latest update or release.
  300. tags : :py:class:`List <list>`\ [\ :py:class:`str`\ ]
  301. Free tag list.
  302. popularity : :py:class:`str`
  303. The popularity of the package, e.g. rating or download count.
  304. license_name : :py:class:`str`
  305. The name of the license.
  306. license_url : :py:class:`str`
  307. The web location of a license copy.
  308. homepage : :py:class:`str`
  309. The url of the project's homepage.
  310. source_code_url: :py:class:`str`
  311. The location of the project's source code.
  312. links : :py:class:`dict`
  313. Additional links in the form of ``{'link_name': 'http://example.com'}``
  314. .. _template code:
  315. ``code.html``
  316. -------------
  317. Displays result fields from:
  318. - :ref:`macro result_header` and
  319. - :ref:`macro result_sub_header`
  320. Additional fields used in the :origin:`code.html
  321. <searx/templates/simple/result_templates/code.html>`:
  322. content : :py:class:`str`
  323. Description of the code fragment.
  324. codelines : ``[line1, line2, ...]``
  325. Lines of the code fragment.
  326. code_language : :py:class:`str`
  327. Name of the code language, the value is passed to
  328. :py:obj:`pygments.lexers.get_lexer_by_name`.
  329. repository : :py:class:`str`
  330. URL of the repository of the code fragment.
  331. .. _template files:
  332. ``files.html``
  333. --------------
  334. Displays result fields from:
  335. - :ref:`macro result_header` and
  336. - :ref:`macro result_sub_header`
  337. Additional fields used in the :origin:`code.html
  338. <searx/templates/simple/result_templates/files.html>`:
  339. filename, size, time: :py:class:`str`
  340. Filename, Filesize and Date of the file.
  341. mtype : ``audio`` | ``video`` | :py:class:`str`
  342. Mimetype type of the file.
  343. subtype : :py:class:`str`
  344. Mimetype / subtype of the file.
  345. abstract : :py:class:`str`
  346. Abstract of the file.
  347. author : :py:class:`str`
  348. Name of the author of the file
  349. embedded : :py:class:`str`
  350. URL of an embedded media type (``audio`` or ``video``) / is collapsible.
  351. .. _template products:
  352. ``products.html``
  353. -----------------
  354. Displays result fields from:
  355. - :ref:`macro result_header` and
  356. - :ref:`macro result_sub_header`
  357. Additional fields used in the :origin:`products.html
  358. <searx/templates/simple/result_templates/products.html>`:
  359. content : :py:class:`str`
  360. Description of the product.
  361. price : :py:class:`str`
  362. The price must include the currency.
  363. shipping : :py:class:`str`
  364. Shipping details.
  365. source_country : :py:class:`str`
  366. Place from which the shipment is made.
  367. .. _template answer results:
  368. Answer results
  369. ==============
  370. See :ref:`result_types.answer`
  371. Suggestion results
  372. ==================
  373. See :ref:`result_types.suggestion`
  374. Correction results
  375. ==================
  376. See :ref:`result_types.corrections`
  377. Infobox results
  378. ===============
  379. See :ref:`result_types.infobox`