Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dl/retro theme #49

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class LinksController < ApplicationController
before_action :authenticate_user!, except: [:index, :show, :user_links, :track_click]
before_action :set_theme, only: [:user_links] # Add this line

def index
@links = Link.order(:position)
Expand Down Expand Up @@ -43,10 +44,27 @@ def destroy

def user_links
@user = User.find_by(username: params[:username])
@links = @user.links.where(visible: true).order(:position)
@pinned_links = @user.links.where(visible: true, pinned: true).order(:position)
@achievements = @user.achievements.order(date: :desc)
return redirect_to root_path, alert: "User not found" if @user.nil?

@links = @user.links
@pinned_links = @user.links.where(pinned: true)
@achievements = @user.achievements
@user.tags = JSON.parse(@user.tags) if @user.tags.is_a?(String)

# Add debugging
Rails.logger.debug "Theme: #{@theme.inspect}"

# Render the appropriate template based on the theme
case @theme
when 'retro'
render 'user_links_retro'
when 'win95'
render 'user_links_win95'
when 'win98'
render 'user_links_win98'
else
render 'user_links'
end
end

def track_click
Expand All @@ -68,4 +86,9 @@ def track_click
def link_params
params.require(:link).permit(:url, :title, :description, :position, :icon, :visible, :pinned)
end

def set_theme
# Determine the theme either from a query parameter or route segment
@theme = params[:theme] || 'default'
end
end
105 changes: 76 additions & 29 deletions app/javascript/entrypoints/application.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,81 @@
// To see this message, add the following to the `<head>` section in your
// views/layouts/application.html.erb
//
// <%= vite_client_tag %>
// <%= vite_javascript_tag 'application' %>
import Rails from "@rails/ujs";
import "chartkick/chart.js"
import "chartkick/chart.js";
import "flowbite";

Rails.start();

console.log('Vite ⚡️ Rails')

// If using a TypeScript entrypoint file:
// <%= vite_typescript_tag 'application' %>
//
// If you want to use .jsx or .tsx, add the extension:
// <%= vite_javascript_tag 'application.jsx' %>

console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify.app/guide/rails')

// Example: Load Rails libraries in Vite.
//
// import * as Turbo from '@hotwired/turbo'
// Turbo.start()
//
// import ActiveStorage from '@rails/activestorage'
// ActiveStorage.start()
//
// // Import all channels.
// const channels = import.meta.globEager('./**/*_channel.js')

// Example: Import a stylesheet in app/frontend/index.css
// import '~/index.css'
console.log('Vite ⚡️ Rails');
console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify.app/guide/rails');

// Linkarooie console messages
console.log('Linkarooie 🌐 Your ultimate link management tool');
console.log('Simplify your online presence with a single link.');
console.log('© 2024 Linkarooie. All rights reserved.');

// Easter egg for "iddqd"
(function () {
let inputBuffer = '';

// Listen for keypress events in the browser
window.addEventListener('keydown', function (event) {
inputBuffer += event.key;

// Check if 'iddqd' was typed
if (inputBuffer.toLowerCase().includes('iddqd')) {
activateGodMode();
inputBuffer = ''; // Reset buffer after activation
}

// Clear the buffer if it gets too long
if (inputBuffer.length > 10) inputBuffer = inputBuffer.slice(-10);
});

function activateGodMode() {
console.log('%c God Mode Activated! You are now invincible! ', 'background: #222; color: #bada55; font-size: 16px;');

// ASCII art
const asciiArt = `
+-----------------------------------------------------------------------------+
| | |\\ -~ / \\ / |
|~~__ | \\ | \\/ /\\ /|
| -- | \\ | / \\ / \\ / |
| |~_| \\ \\___|/ \\/ / |
|--__ | -- |\\________________________________/~~\\~~| / \\ / \\ |
| |~~--__ |~_|____|____|____|____|____|____|/ / \\/|\\ / \\/ \\/|
| | |~--_|__|____|____|____|____|____|_/ /| |/ \\ / \\ / |
|___|______|__|_||____|____|____|____|____|__[]/_|----| \\/ \\ / |
| \\mmmm : | _|___|____|____|____|____|____|___| /\\| / \\ / \\ |
| B :_--~~ |_|____|____|____|____|____|____| | |\\/ \\ / \\ |
| __--P : | / / / | \\ / \\ /\\|
|~~ | : | / ~~~ | \\ / \\ / |
| | |/ .-. | /\\ \\ / |
| | / | | |/ \\ /\\ |
| | / | | -_ \\ / \\ |
+-----------------------------------------------------------------------------+
| | /| | | 2 3 4 | /~~~~~\\ | /| |_| .... ......... |
| | ~|~ | % | | | ~J~ | | ~|~ % |_| .... ......... |
| AMMO | HEALTH | 5 6 7 | \\===/ | ARMOR |#| .... ......... |
+-----------------------------------------------------------------------------+
`;

console.log(asciiArt);

// Create a div to display Doom information
const infoDiv = document.createElement('div');
infoDiv.innerHTML = `
<div style="position: fixed; bottom: 20px; right: 20px; background-color: #111; color: #fff; padding: 20px; border-radius: 10px; max-width: 300px; z-index: 1000;">
<h3 style="margin: 0 0 10px 0;">You've unlocked a secret!</h3>
<p>Doom is a 1993 first-person shooter game developed by id Software. It was created by John Carmack and John Romero, among others. The game is considered one of the most significant titles in video game history, pioneering immersive 3D graphics, networked multiplayer gaming, and support for custom mods and expansions.</p>
<p>The "iddqd" command is a famous cheat code that grants invulnerability, often referred to as "God Mode".</p>
<p>Fun Fact: The name "Doom" was inspired by a line from the movie "The Color of Money" starring Tom Cruise.</p>
<button id="closeInfo" style="margin-top: 10px; padding: 5px 10px; background-color: #555; color: #fff; border: none; cursor: pointer;">Close</button>
</div>
`;
document.body.appendChild(infoDiv);

// Add event listener to the close button to remove the div
document.getElementById('closeInfo').addEventListener('click', function() {
document.body.removeChild(infoDiv);
});
}
})();
19 changes: 13 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
Rails.application.routes.draw do
get 'analytics/index'
# Use the custom registrations controller in all environments

# Devise routes for user registration
devise_for :users, controllers: {
registrations: 'users/registrations'
}

# Routes for links with standard RESTful actions
resources :links do
member do
get :track_click
end
end

# Sidekiq monitoring
require 'sidekiq/web'
require 'sidekiq-scheduler/web'
mount Sidekiq::Web => '/sidekiq'

# Other routes
# Custom routes for user-specific views and analytics
get '/:username/analytics', to: 'analytics#index', as: :user_analytics
get "up" => "rails/health#show", as: :rails_health_check
get '/:username(/:theme)', to: 'links#user_links', as: :user_links, constraints: { theme: /retro|win95|win98/ }

# Health check route
get 'up' => 'rails/health#show', as: :rails_health_check

# Root route
root to: 'pages#home'
resources :links, only: [:index, :show, :new, :create, :edit, :update, :destroy]

# Additional resources
resources :achievements, only: [:index, :show, :new, :create, :edit, :update, :destroy]
get '/:username', to: 'links#user_links', as: 'user_links'
end
Loading