@@ -71,24 +71,28 @@ def set_page
7171 end
7272
7373 def save_tailwind_page_content
74- Puppeteer . launch (
75- headless : true ,
76- args : [ '--no-sandbox' , '--disable-setuid-sandbox' ]
77- ) do |browser |
78- page = browser . pages . first || browser . new_page
79- page . goto ( root_url )
80- cookies . each do |name , value |
81- page . set_cookie ( name : name , value : value )
82- end
83- page . goto ( event_staff_page_url ( current_event , @page ) , wait_until : 'domcontentloaded' )
84- css = page . query_selector_all ( 'style' ) . map do |style |
85- style . evaluate ( '(el) => el.textContent' )
86- end . detect { |text | text . match ( "tailwindcss" ) }
87- html = "<style>#{ css } </style>"
88-
89- content = @page . contents . find_or_initialize_by ( name : Page ::TAILWIND )
90- content . update! ( placement : Website ::Content ::HEAD , html : html )
74+ @body = @page . unpublished_body
75+ content = render_to_string ( template : 'pages/show' , layout : "themes/#{ current_website . theme } " )
76+ command = [ "yarn run tailwindcss --minify" ]
77+ page_file = Tempfile . new ( [ 'page_content' , '.html' ] , 'tmp' )
78+ page_file . write ( content )
79+ page_file . close
80+ command . push ( "--content" , page_file . path )
81+ if tailwind_config = current_website . tailwind_config
82+ config_file = Tempfile . new ( [ 'config_file' , '.js' ] , 'tmp' )
83+ config_file . write ( tailwind_config )
84+ config_file . close
85+ command . push ( "--config" , config_file . path )
9186 end
87+ output = `#{ command . join ( ' ' ) } `
88+ css = output . match ( /(\/ \* ! tailwindcss .*)/m )
89+ html = "<style>#{ css } </style>"
90+
91+ content = @page . contents . find_or_initialize_by ( name : Page ::TAILWIND )
92+ content . update! ( placement : Website ::Content ::HEAD , html : html )
93+ ensure
94+ page_file &.unlink
95+ config_file &.unlink
9296 end
9397
9498 def build_page
0 commit comments