11use crate :: db:: read:: Entry ;
2- use crate :: env;
32use crate :: errors:: Error ;
4- use askama:: Template ;
53use sha2:: { Digest , Sha256 } ;
64use std:: cmp:: Ordering ;
7- use std:: io:: Cursor ;
85use std:: sync:: LazyLock ;
9- use syntect:: highlighting:: { Color , ThemeSet } ;
10- use syntect:: html:: { css_for_theme_with_class_style, line_tokens_to_classed_spans, ClassStyle } ;
6+ use syntect:: html:: { line_tokens_to_classed_spans, ClassStyle } ;
117use syntect:: parsing:: { ParseState , ScopeStack , SyntaxReference , SyntaxSet } ;
128use syntect:: util:: LinesWithEndings ;
13- use two_face:: theme:: EmbeddedThemeName ;
149
1510const HIGHLIGHT_LINE_LENGTH_CUTOFF : usize = 2048 ;
1611
@@ -25,109 +20,10 @@ pub enum Theme {
2520 Solarized ,
2621}
2722
28- // #[derive(Template)]
29- // #[template(path = "style.css", escape = "none")]
30- // struct StyleCss {
31- // light_background: Color,
32- // light_foreground: Color,
33- // dark_background: Color,
34- // dark_foreground: Color,
35- // }
36-
3723#[ derive( Clone ) ]
3824pub struct Html ( String ) ;
3925
40- pub static LIGHT_THEME : LazyLock < syntect:: highlighting:: Theme > = LazyLock :: new ( || {
41- let theme_set = two_face:: theme:: extra ( ) ;
42-
43- match * env:: THEME {
44- Theme :: Ayu => {
45- let theme = include_str ! ( "themes/ayu-light.tmTheme" ) ;
46- ThemeSet :: load_from_reader ( & mut Cursor :: new ( theme) ) . expect ( "loading theme" )
47- }
48- Theme :: Base16Ocean => theme_set. get ( EmbeddedThemeName :: Base16OceanLight ) . clone ( ) ,
49- Theme :: Coldark => theme_set. get ( EmbeddedThemeName :: ColdarkCold ) . clone ( ) ,
50- Theme :: Gruvbox => theme_set. get ( EmbeddedThemeName :: GruvboxLight ) . clone ( ) ,
51- Theme :: Monokai => theme_set
52- . get ( EmbeddedThemeName :: MonokaiExtendedLight )
53- . clone ( ) ,
54- Theme :: Onehalf => theme_set. get ( EmbeddedThemeName :: OneHalfLight ) . clone ( ) ,
55- Theme :: Solarized => theme_set. get ( EmbeddedThemeName :: SolarizedLight ) . clone ( ) ,
56- }
57- } ) ;
58-
59- pub static LIGHT_CSS : LazyLock < String > = LazyLock :: new ( || {
60- css_for_theme_with_class_style ( & LIGHT_THEME , ClassStyle :: Spaced ) . expect ( "generating CSS" )
61- } ) ;
62-
63- pub static DARK_THEME : LazyLock < syntect:: highlighting:: Theme > = LazyLock :: new ( || {
64- let theme_set = two_face:: theme:: extra ( ) ;
65-
66- match * env:: THEME {
67- Theme :: Ayu => {
68- let theme = include_str ! ( "themes/ayu-dark.tmTheme" ) ;
69- ThemeSet :: load_from_reader ( & mut Cursor :: new ( theme) ) . expect ( "loading theme" )
70- }
71- Theme :: Base16Ocean => theme_set. get ( EmbeddedThemeName :: Base16OceanDark ) . clone ( ) ,
72- Theme :: Coldark => theme_set. get ( EmbeddedThemeName :: ColdarkDark ) . clone ( ) ,
73- Theme :: Gruvbox => theme_set. get ( EmbeddedThemeName :: GruvboxDark ) . clone ( ) ,
74- Theme :: Monokai => theme_set. get ( EmbeddedThemeName :: MonokaiExtended ) . clone ( ) ,
75- Theme :: Onehalf => theme_set. get ( EmbeddedThemeName :: OneHalfDark ) . clone ( ) ,
76- Theme :: Solarized => theme_set. get ( EmbeddedThemeName :: SolarizedDark ) . clone ( ) ,
77- }
78- } ) ;
79-
80- pub static DARK_CSS : LazyLock < String > = LazyLock :: new ( || {
81- css_for_theme_with_class_style ( & DARK_THEME , ClassStyle :: Spaced ) . expect ( "generating CSS" )
82- } ) ;
83-
84- trait ColorExt {
85- fn new ( r : u8 , g : u8 , b : u8 , a : u8 ) -> Self ;
86- }
87-
88- impl ColorExt for Color {
89- fn new ( r : u8 , g : u8 , b : u8 , a : u8 ) -> Self {
90- Self { r, g, b, a }
91- }
92- }
93-
94- pub static STYLE_CSS : LazyLock < String > = LazyLock :: new ( || {
95- let light_foreground = LIGHT_THEME
96- . settings
97- . foreground
98- . unwrap_or ( Color :: new ( 3 , 3 , 3 , 100 ) ) ;
99-
100- let light_background = LIGHT_THEME
101- . settings
102- . background
103- . unwrap_or ( Color :: new ( 250 , 250 , 250 , 100 ) ) ;
104-
105- let dark_foreground = DARK_THEME
106- . settings
107- . foreground
108- . unwrap_or ( Color :: new ( 230 , 225 , 207 , 100 ) ) ;
109-
110- let dark_background = DARK_THEME
111- . settings
112- . background
113- . unwrap_or ( Color :: new ( 15 , 20 , 25 , 100 ) ) ;
114-
115- String :: from ( "hello" )
116- //
117- // let style = StyleCss {
118- // light_background,
119- // light_foreground,
120- // dark_background,
121- // dark_foreground,
122- // };
123- //
124- // style.render().expect("rendering style css")
125- } ) ;
126-
12726pub static DATA : LazyLock < Data > = LazyLock :: new ( || {
128- let style = Hashed :: new ( "style" , "css" , & STYLE_CSS ) ;
129- let index = Hashed :: new ( "index" , "js" , include_str ! ( "javascript/index.js" ) ) ;
130- let paste = Hashed :: new ( "paste" , "js" , include_str ! ( "javascript/paste.js" ) ) ;
13127 let syntax_set = two_face:: syntax:: extra_newlines ( ) ;
13228 let mut syntaxes = syntax_set. syntaxes ( ) . to_vec ( ) ;
13329 syntaxes. sort_by ( |a, b| {
@@ -138,9 +34,6 @@ pub static DATA: LazyLock<Data> = LazyLock::new(|| {
13834 } ) ;
13935
14036 Data {
141- style,
142- index,
143- paste,
14437 syntax_set,
14538 syntaxes,
14639 }
@@ -152,10 +45,7 @@ pub struct Hashed<'a> {
15245 pub content : & ' a str ,
15346}
15447
155- pub struct Data < ' a > {
156- pub style : Hashed < ' a > ,
157- pub index : Hashed < ' a > ,
158- pub paste : Hashed < ' a > ,
48+ pub struct Data {
15949 pub syntax_set : SyntaxSet ,
16050 pub syntaxes : Vec < SyntaxReference > ,
16151}
0 commit comments