Compare commits

..

22 commits

Author SHA1 Message Date
fb6d49cc6e Merge pull request 'GPU acceleration for the mobile menu' (#818) from gpu-acceleration into main
Reviewed-on: Plume/Plume#818
Reviewed-by: kiwii <kiwii@noreply@joinplu.me>
2020-08-27 10:29:34 +00:00
48776939f4 Merge branch 'main' into gpu-acceleration 2020-08-19 19:53:39 +00:00
Marek Ľach
104b6c1d0c
GPU acceleration for the mobile menu
Reimplements #810, but for all browsers.
2020-08-19 21:34:07 +02:00
3881927550 Merge pull request 'mobile-margins' (#817) from mobile-margins into main
Reviewed-on: Plume/Plume#817
Reviewed-by: Mina Galić <me+git@igalic.co>
2020-08-19 11:35:04 +00:00
0bec13edc0 Improve responsiveness 2020-08-11 20:13:27 +02:00
191d6da486 Move header-related style to _header.scss
It seems to fix the overflowing menu items on small screens too
2020-08-11 20:13:27 +02:00
9aaff1a484 Merge pull request 'Use result of local storage insert operation to suppress Clippy' (#810) from KitaitiMakoto/Plume:suppress-clippy into main
Reviewed-on: Plume/Plume#810
Reviewed-by: kiwii <kiwii@noreply@joinplu.me>
2020-07-25 17:28:26 +00:00
36fd55a7e4 Use result of local storage insert operation to suppress Clippy 2020-07-25 20:13:41 +09:00
fc474bf8d1 Merge pull request '[BUG FIX]Make it possible to switch to rich text editor' (#808) from KitaitiMakoto/Plume:richtexteditor into main
Reviewed-on: Plume/Plume#808
Reviewed-by: kiwii <kiwii@noreply@joinplu.me>
2020-07-23 18:25:53 +00:00
a050deb557 [BUG FIX]Make it possible to switch to rich text editor 2020-07-23 23:36:09 +09:00
6de9a1f1c8 Merge pull request 'Recreate search index if its format is outdated' (#802) from KitaitiMakoto/Plume:invalid-index into main
Reviewed-on: Plume/Plume#802
Reviewed-by: Mina Galić <me+git@igalic.co>
2020-07-19 12:04:43 +00:00
5e30bede40 Don't care about needless return value of closures 2020-07-19 08:24:17 +09:00
5cca66b346 Add action user can take to error message 2020-07-19 07:16:34 +09:00
484659fde2 Run cargo fmt 2020-07-18 22:52:39 +09:00
5fc827c1c9 Re-initialize search index when recreating is failed 2020-07-18 21:00:58 +09:00
50753b3a65 Recreate search index if its format is outdated 2020-07-18 09:40:58 +09:00
c5d03d300b Cause IndexInvalidDataError when search index is invalid 2020-07-18 09:40:47 +09:00
010eac6c4a Merge pull request 'upgrade rocket* to the latest stable' (#800) from igalic/Plume:update/rocket into main
Reviewed-on: Plume/Plume#800
Reviewed-by: kiwii <kiwii@noreply@joinplu.me>
2020-07-17 13:39:12 +00:00
a107d35492
upgrade rocket* to the latest stable
before we embark on upgrading to async, and all the refactoring that
this will bring on us (see #797 & #799), we should keep our `main`
branch as stable and current as possible.
Let's start by upgrading rocket and its dependencies.
2020-07-17 09:38:55 +02:00
f9beb2383b Update lindera-tantivy to v0.1.3 2020-07-05 17:59:51 +02:00
Chosto
7e78cffcaa
Bump Docker base images to buster flavor (#797) 2020-07-02 12:46:56 +02:00
TheMasix
28576c1fa3
Add Vazir Font (#787)
* Add Vazir Font

* Add Vazir Font License

* fix prettier problem

* Shabnam added
2020-06-24 15:48:04 +02:00
66 changed files with 1527 additions and 862 deletions

1875
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -20,8 +20,8 @@ heck = "0.3.0"
lettre = "0.9.2"
lettre_email = "0.9.2"
num_cpus = "1.10"
rocket = "0.4.2"
rocket_contrib = { version = "0.4.2", features = ["json"] }
rocket = "0.4.5"
rocket_contrib = { version = "0.4.5", features = ["json"] }
rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" }
rpassword = "4.0"
scheduled-thread-pool = "0.2.2"

View file

@ -1,4 +1,4 @@
FROM rust:1-stretch as builder
FROM rust:1-buster as builder
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
@ -28,7 +28,7 @@ RUN cargo install --path ./ --force --no-default-features --features postgres
RUN cargo install --path plume-cli --force --no-default-features --features postgres
RUN cargo clean
FROM debian:stretch-slim
FROM debian:buster-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \

View file

@ -1,4 +1,4 @@
FROM rust:1-stretch
FROM rust:1-buster
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \

View file

@ -490,3 +490,30 @@ input:checked ~ .cw-container > .cw-text {
display: inline;
}
}
// Small screens
@media screen and (max-width: 600px) {
#plume-editor header {
flex-direction: column-reverse;
button {
flex: 0 0 0;
}
}
.popup {
top: 10vh;
bottom: 10vh;
left: 1vw;
right: 1vw;
}
main article {
margin: 2.5em .5em;
max-width: none;
}
main .article-meta > *, main .article-meta .comments, main .article-meta > .banner > * {
margin: 0 5%;
}
}

View file

@ -490,6 +490,10 @@ figure {
/// Small screens
@media screen and (max-width: 600px) {
body > main > *, .h-feed > * {
margin: 1em;
}
main .article-meta {
> *, .comments {
margin: 0 5%;
@ -535,7 +539,7 @@ figure {
margin: 0;
& > * {
max-width: 100%;
max-width: 100% !important;
}
}

View file

@ -205,6 +205,7 @@ body > header {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
transform: translateZ(0);
opacity: 0;
font-size: 0.9em;
white-space: nowrap;
@ -221,3 +222,93 @@ body > header {
}
}
}
// Small screens
@media screen and (max-width: 600px) {
@keyframes menuOpening {
from {
transform: scaleX(0);
transform-origin: left;
opacity: 0;
}
to {
transform: scaleX(1);
transform-origin: left;
opacity: 1;
}
}
body > header {
flex-direction: column;
nav#menu {
display: inline-flex;
z-index: 21;
}
#content {
display: none;
appearance: none;
text-align: center;
z-index: 20;
}
}
body > header:focus-within #content, #content.show {
position: fixed;
display: flex;
flex-direction: column;
justify-content: flex-start;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
animation: 0.2s menuOpening;
&::before {
content: "";
position: absolute;
transform: skewX(-10deg);
top: 0;
left: -20%;
width: 100%;
height: 100%;
z-index: -10;
background: $primary;
}
> nav {
flex-direction: column;
align-items: flex-start;
a {
display: flex;
flex-direction: row;
align-items: center;
margin: 0;
padding: 1rem 1.5rem;
color: $background;
font-size: 1.4em;
font-weight: 300;
&.title { font-size: 1.8em; }
> *:first-child { width: 3rem; }
> img:first-child { height: 3rem; }
> *:last-child { margin-left: 1rem; }
> nav hr {
display: block;
margin: 0;
width: 100%;
border: solid $background 0.1rem;
}
.mobile-label { display: initial; }
}
}
}
}

View file

@ -1,10 +1,10 @@
/* Color Scheme */
$gray: #F3F3F3;
$gray: #f3f3f3;
$black: #242424;
$white: #F8F8F8;
$purple: #7765E3;
$white: #f8f8f8;
$purple: #7765e3;
$lightpurple: #c2bbee;
$red: #E92F2F;
$red: #e92f2f;
$yellow: #ffe347;
$green: #23f0c7;
@ -24,14 +24,14 @@ $margin: 0 $horizontal-margin;
/* Fonts */
$route159: "Route159", serif;
$playfair: "Playfair Display", serif;
$lora: "Lora", serif;
$route159: "Shabnam", "Route159", serif;
$playfair: "Vazir", "Playfair Display", serif;
$lora: "Vazir", "Lora", serif;
//Code Highlighting
$code-keyword-color: #45244a;
$code-source-color: #4c588c;
$code-constant-color: scale-color(magenta,$lightness:-5%);
$code-operator-color: scale-color($code-source-color,$lightness:-5%);
$code-constant-color: scale-color(magenta, $lightness: -5%);
$code-operator-color: scale-color($code-source-color, $lightness: -5%);
$code-string-color: #8a571c;
$code-comment-color: #1c4c8a;

View file

@ -1,12 +1,14 @@
/* color palette: https://coolors.co/23f0c7-ef767a-7765e3-6457a6-ffe347 */
@import url('./feather.css');
@import url('./fonts/Route159/Route159.css');
@import url('./fonts/Lora/Lora.css');
@import url('./fonts/Playfair_Display/PlayfairDisplay.css');
@import url("./feather.css");
@import url("./fonts/Route159/Route159.css");
@import url("./fonts/Lora/Lora.css");
@import url("./fonts/Playfair_Display/PlayfairDisplay.css");
@import url("./fonts/Vazir_WOL/Vazir_WOL.css");
@import url("./fonts/Shabnam_WOL/Shabnam_WOL.css");
@import 'dark_variables';
@import 'global';
@import 'header';
@import 'article';
@import 'forms';
@import "dark_variables";
@import "global";
@import "header";
@import "article";
@import "forms";

View file

@ -0,0 +1,94 @@
Copyright (c) 2015, Saber Rastikerdar (saber.rastikerdar@gmail.com),
Glyphs and data from Roboto font are licensed under the Apache License, Version 2.0.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View file

@ -0,0 +1,49 @@
@font-face {
font-family: Shabnam;
src: url("Shabnam-WOL.eot");
src: url("Shabnam-WOL.eot?#iefix") format("embedded-opentype"),
url("Shabnam-WOL.woff2") format("woff2"),
url("Shabnam-WOL.woff") format("woff"),
url("Shabnam-WOL.ttf") format("truetype");
font-weight: normal;
}
@font-face {
font-family: Shabnam;
src: url("Shabnam-Bold-WOL.eot");
src: url("Shabnam-Bold-WOL.eot?#iefix") format("embedded-opentype"),
url("Shabnam-Bold-WOL.woff2") format("woff2"),
url("Shabnam-Bold-WOL.woff") format("woff"),
url("Shabnam-Bold-WOL.ttf") format("truetype");
font-weight: bold;
}
@font-face {
font-family: Shabnam;
src: url("Shabnam-Thin-WOL.eot");
src: url("Shabnam-Thin-WOL.eot?#iefix") format("embedded-opentype"),
url("Shabnam-Thin-WOL.woff2") format("woff2"),
url("Shabnam-Thin-WOL.woff") format("woff"),
url("Shabnam-Thin-WOL.ttf") format("truetype");
font-weight: 100;
}
@font-face {
font-family: Shabnam;
src: url("Shabnam-Light-WOL.eot");
src: url("Shabnam-Light-WOL.eot?#iefix") format("embedded-opentype"),
url("Shabnam-Light-WOL.woff2") format("woff2"),
url("Shabnam-Light-WOL.woff") format("woff"),
url("Shabnam-Light-WOL.ttf") format("truetype");
font-weight: 300;
}
@font-face {
font-family: Shabnam;
src: url("Shabnam-Medium-WOL.eot");
src: url("Shabnam-Medium-WOL.eot?#iefix") format("embedded-opentype"),
url("Shabnam-Medium-WOL.woff2") format("woff2"),
url("Shabnam-Medium-WOL.woff") format("woff"),
url("Shabnam-Medium-WOL.ttf") format("truetype");
font-weight: 500;
}

View file

@ -0,0 +1,51 @@
Changes by Saber Rastikerdar (saber.rastikerdar@gmail.com) are in public domain.
Glyphs and data from Roboto font are licensed under the Apache License, Version 2.0.
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Bitstream Vera Fonts Copyright
------------------------------
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:
The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".
This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.
The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.
Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,65 @@
@font-face {
font-family: Vazir;
src: url('Vazir-WOL.eot');
src: url('Vazir-WOL.eot?#iefix') format('embedded-opentype'),
url('Vazir-WOL.woff2') format('woff2'),
url('Vazir-WOL.woff') format('woff'),
url('Vazir-WOL.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: Vazir;
src: url('Vazir-Bold-WOL.eot');
src: url('Vazir-Bold-WOL.eot?#iefix') format('embedded-opentype'),
url('Vazir-Bold-WOL.woff2') format('woff2'),
url('Vazir-Bold-WOL.woff') format('woff'),
url('Vazir-Bold-WOL.ttf') format('truetype');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: Vazir;
src: url('Vazir-Black-WOL.eot');
src: url('Vazir-Black-WOL.eot?#iefix') format('embedded-opentype'),
url('Vazir-Black-WOL.woff2') format('woff2'),
url('Vazir-Black-WOL.woff') format('woff'),
url('Vazir-Black-WOL.ttf') format('truetype');
font-weight: 900;
font-style: normal;
}
@font-face {
font-family: Vazir;
src: url('Vazir-Medium-WOL.eot');
src: url('Vazir-Medium-WOL.eot?#iefix') format('embedded-opentype'),
url('Vazir-Medium-WOL.woff2') format('woff2'),
url('Vazir-Medium-WOL.woff') format('woff'),
url('Vazir-Medium-WOL.ttf') format('truetype');
font-weight: 500;
font-style: normal;
}
@font-face {
font-family: Vazir;
src: url('Vazir-Light-WOL.eot');
src: url('Vazir-Light-WOL.eot?#iefix') format('embedded-opentype'),
url('Vazir-Light-WOL.woff2') format('woff2'),
url('Vazir-Light-WOL.woff') format('woff'),
url('Vazir-Light-WOL.ttf') format('truetype');
font-weight: 300;
font-style: normal;
}
@font-face {
font-family: Vazir;
src: url('Vazir-Thin-WOL.eot');
src: url('Vazir-Thin-WOL.eot?#iefix') format('embedded-opentype'),
url('Vazir-Thin-WOL.woff2') format('woff2'),
url('Vazir-Thin-WOL.woff') format('woff'),
url('Vazir-Thin-WOL.ttf') format('truetype');
font-weight: 100;
font-style: normal;
}

View file

@ -1,12 +1,14 @@
/* color palette: https://coolors.co/23f0c7-ef767a-7765e3-6457a6-ffe347 */
@import url('./feather.css');
@import url('./fonts/Route159/Route159.css');
@import url('./fonts/Lora/Lora.css');
@import url('./fonts/Playfair_Display/PlayfairDisplay.css');
@import url("./feather.css");
@import url("./fonts/Route159/Route159.css");
@import url("./fonts/Lora/Lora.css");
@import url("./fonts/Playfair_Display/PlayfairDisplay.css");
@import url("./fonts/Vazir_WOL/Vazir_WOL.css");
@import url("./fonts/Shabnam_WOL/Shabnam_WOL.css");
@import 'variables';
@import 'global';
@import 'header';
@import 'article';
@import 'forms';
@import "variables";
@import "global";
@import "header";
@import "article";
@import "forms";

View file

@ -14,7 +14,7 @@ heck = "0.3.0"
hex = "0.3"
hyper = "0.12.33"
openssl = "0.10.22"
rocket = "0.4.0"
rocket = "0.4.5"
reqwest = "0.9"
serde = "1.0"
serde_derive = "1.0"

View file

@ -269,7 +269,13 @@ pub fn init() -> Result<(), EditorError> {
let editor_button = document().create_element("a")?;
js! { @{&editor_button}.href = "#"; }
editor_button.add_event_listener(|_: ClickEvent| {
window().local_storage().remove("basic-editor");
if window()
.local_storage()
.insert("basic-editor", "false")
.is_err()
{
console!(log, "Failed to write into local storage");
}
window().history().go(0).ok(); // refresh
});
editor_button.append_child(

View file

@ -46,9 +46,6 @@ lazy_static! {
let lang = js! { return navigator.language }.into_string().unwrap();
let lang = lang.splitn(2, '-').next().unwrap_or("en");
// Force a language (Add .env setting)
//let lang = "fa"; ???
let english_position = catalogs
.iter()
.position(|(language_code, _)| *language_code == "en")

View file

@ -15,7 +15,7 @@ itertools = "0.8.0"
lazy_static = "1.0"
migrations_internals= "1.4.0"
openssl = "0.10.22"
rocket = "0.4.0"
rocket = "0.4.5"
rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" }
reqwest = "0.9"
scheduled-thread-pool = "0.2.2"
@ -30,7 +30,7 @@ whatlang = "0.7.1"
shrinkwraprs = "0.2.1"
diesel-derive-newtype = "0.1.2"
glob = "0.3.0"
lindera-tantivy = { version = "0.1.2", optional = true }
lindera-tantivy = { version = "0.1.3", optional = true }
[dependencies.chrono]
features = ["serde"]

Binary file not shown.

Binary file not shown.

View file

@ -5,10 +5,10 @@ use crate::{
use chrono::Datelike;
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl};
use itertools::Itertools;
use std::{cmp, fs::create_dir_all, path::Path, sync::Mutex};
use std::{cmp, fs::create_dir_all, io, path::Path, sync::Mutex};
use tantivy::{
collector::TopDocs, directory::MmapDirectory, schema::*, Index, IndexReader, IndexWriter,
ReloadPolicy, Term,
ReloadPolicy, TantivyError, Term,
};
use whatlang::{detect as detect_lang, Lang};
@ -18,6 +18,7 @@ pub enum SearcherError {
WriteLockAcquisitionError,
IndexOpeningError,
IndexEditionError,
InvalidIndexDataError,
}
pub struct Searcher {
@ -135,7 +136,19 @@ impl Searcher {
.reader_builder()
.reload_policy(ReloadPolicy::Manual)
.try_into()
.map_err(|_| SearcherError::IndexCreationError)?,
.map_err(|e| {
if let TantivyError::IOError(err) = e {
let err: io::Error = err.into();
if err.kind() == io::ErrorKind::InvalidData {
// Search index was created in older Tantivy format.
SearcherError::InvalidIndexDataError
} else {
SearcherError::IndexCreationError
}
} else {
SearcherError::IndexCreationError
}
})?,
index,
})
}

27
src/main.rs Normal file → Executable file
View file

@ -10,6 +10,7 @@ extern crate serde_json;
#[macro_use]
extern crate validator_derive;
use chrono::Utc;
use clap::App;
use diesel::r2d2::ConnectionManager;
use plume_models::{
@ -21,6 +22,8 @@ use plume_models::{
};
use rocket_csrf::CsrfFairingBuilder;
use scheduled_thread_pool::ScheduledThreadPool;
use std::fs;
use std::path::Path;
use std::process::exit;
use std::sync::{Arc, Mutex};
use std::time::Duration;
@ -98,8 +101,30 @@ Then try to restart Plume.
}
let workpool = ScheduledThreadPool::with_name("worker {}", num_cpus::get());
// we want a fast exit here, so
let mut open_searcher =
UnmanagedSearcher::open(&CONFIG.search_index, &CONFIG.search_tokenizers);
if let Err(Error::Search(SearcherError::InvalidIndexDataError)) = open_searcher {
if UnmanagedSearcher::create(&CONFIG.search_index, &CONFIG.search_tokenizers).is_err() {
let current_path = Path::new(&CONFIG.search_index);
let backup_path = format!("{}.{}", &current_path.display(), Utc::now().timestamp());
let backup_path = Path::new(&backup_path);
fs::rename(current_path, backup_path)
.expect("main: error on backing up search index directory for recreating");
if UnmanagedSearcher::create(&CONFIG.search_index, &CONFIG.search_tokenizers).is_ok() {
if fs::remove_dir_all(backup_path).is_err() {
eprintln!(
"error on removing backup directory: {}. it remains",
backup_path.display()
);
}
} else {
panic!("main: error on recreating search index in new index format. remove search index and run `plm search init` manually");
}
}
open_searcher = UnmanagedSearcher::open(&CONFIG.search_index, &CONFIG.search_tokenizers);
}
#[allow(clippy::match_wild_err_arm)]
let searcher = match UnmanagedSearcher::open(&CONFIG.search_index, &CONFIG.search_tokenizers) {
let searcher = match open_searcher {
Err(Error::Search(e)) => match e {
SearcherError::WriteLockAcquisitionError => panic!(
r#"